<?php
/**
 * 微商城模块微站定义
 *
 * @author WeEngine Team
 * @url
 */
defined('IN_IA') or exit('Access Denied');

session_start();
include 'model.php';
if(!function_exists('M')){
    function M($name){
        static $model = array();
        if(empty($model[$name])) {
            include IA_ROOT.'/addons/deng/model/'.$name.'.php';
            $model[$name] = new $name();
        }
        return $model[$name];
    }
}
class DengModuleSite extends WeModuleSite {

	public $settings;

	public function __construct() {
		global $_W;
		$sql = 'SELECT `settings` FROM ' . tablename('uni_account_modules') . ' WHERE `uniacid` = :uniacid AND `module` = :module';
		$settings = pdo_fetchcolumn($sql, array(':uniacid' => $_W['uniacid'], ':module' => 'ewei_shopping'));
		$this->settings = iunserializer($settings);
		
	}

	public function doWebCategory() {
		global $_GPC, $_W;
		load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			if (!empty($_GPC['displayorder'])) {
				foreach ($_GPC['displayorder'] as $id => $displayorder) {
					pdo_update('shopping_category', array('displayorder' => $displayorder), array('id' => $id, 'weid' => $_W['uniacid']));
				}
				message('分类排序更新成功！', $this->createWebUrl('category', array('op' => 'display')), 'success');
			}
			$children = array();
			$category = pdo_fetchall("SELECT * FROM " . tablename('shopping_category') . " WHERE weid = '{$_W['uniacid']}' ORDER BY parentid ASC, displayorder DESC");
			foreach ($category as $index => $row) {
				if (!empty($row['parentid'])) {
					$children[$row['parentid']][] = $row;
					unset($category[$index]);
				}
			}
			include $this->template('category');
		} elseif ($operation == 'post') {
			$parentid = intval($_GPC['parentid']);
			$id = intval($_GPC['id']);
			if (!empty($id)) {
				$category = pdo_fetch("SELECT * FROM " . tablename('shopping_category') . " WHERE id = :id AND weid = :weid", array(':id' => $id, ':weid' => $_W['uniacid']));
			} else {
				$category = array(
					'displayorder' => 0,
				);
			}
			if (!empty($parentid)) {
				$parent = pdo_fetch("SELECT id, name FROM " . tablename('shopping_category') . " WHERE id = '$parentid'");
				if (empty($parent)) {
					message('抱歉，上级分类不存在或是已经被删除！', $this->createWebUrl('post'), 'error');
				}
			}
			if (checksubmit('submit')) {
				if (empty($_GPC['catename'])) {
					message('抱歉，请输入分类名称！');
				}
				$data = array(
					'weid' => $_W['uniacid'],
					'name' => $_GPC['catename'],
					'enabled' => intval($_GPC['enabled']),
					'displayorder' => intval($_GPC['displayorder']),
					'isrecommand' => intval($_GPC['isrecommand']),
					'description' => $_GPC['description'],
					'parentid' => intval($parentid),
					'thumb' => $_GPC['thumb']
				);
				if (!empty($id)) {
					unset($data['parentid']);
					pdo_update('shopping_category', $data, array('id' => $id, 'weid' => $_W['uniacid']));
					load()->func('file');
					file_delete($_GPC['thumb_old']);
				} else {
					pdo_insert('shopping_category', $data);
					$id = pdo_insertid();
				}
				message('更新分类成功！', $this->createWebUrl('category', array('op' => 'display')), 'success');
			}
			include $this->template('category');
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$category = pdo_fetch("SELECT id, parentid FROM " . tablename('shopping_category') . " WHERE id = '$id'");
			if (empty($category)) {
				message('抱歉，分类不存在或是已经被删除！', $this->createWebUrl('category', array('op' => 'display')), 'error');
			}
			pdo_delete('shopping_category', array('id' => $id, 'parentid' => $id), 'OR');
			message('分类删除成功！', $this->createWebUrl('category', array('op' => 'display')), 'success');
		}
	}


	public function doWebSetGoodsProperty() {
		global $_GPC, $_W;
		$id = intval($_GPC['id']);
		$type = $_GPC['type'];
		$data = intval($_GPC['data']);
		if (in_array($type, array('new', 'hot', 'recommand', 'discount'))) {
			$data = ($data==1?'0':'1');
			pdo_update("shopping_goods", array("is" . $type => $data), array("id" => $id, "weid" => $_W['uniacid']));
			die(json_encode(array("result" => 1, "data" => $data)));
		}
		if (in_array($type, array('status'))) {
			$data = ($data==1?'0':'1');
			pdo_update("shopping_goods", array($type => $data), array("id" => $id, "weid" => $_W['uniacid']));
			die(json_encode(array("result" => 1, "data" => $data)));
		}
		if (in_array($type, array('type'))) {
			$data = ($data==1?'2':'1');
			pdo_update("shopping_goods", array($type => $data), array("id" => $id, "weid" => $_W['uniacid']));
			die(json_encode(array("result" => 1, "data" => $data)));
		}
		die(json_encode(array("result" => 0)));
	}
	public function doWebSetOrdersProperty() {
		global $_GPC, $_W;
		$id = intval($_GPC['id']);
		$type = $_GPC['type'];
		$data = intval($_GPC['data']);
		
		if (in_array($type, array('isshow'))) {
			$data = ($data==1?'0':'1');
			pdo_update("shopping_order", array($type => $data), array("id" => $id));
			die(json_encode(array("result" => 1, "data" => $data)));
		}
		
		die(json_encode(array("result" => 0)));
	}
	public function doWebSetOrdercommentsProperty() {
		global $_GPC, $_W;
		$id = intval($_GPC['id']);
		$type = $_GPC['type'];
		$data = intval($_GPC['data']);
		
		if (in_array($type, array('shows'))) {
			$data = ($data==1?'0':'1');
			pdo_update("shopping_comment", array($type => $data), array("id" => $id));
			die(json_encode(array("result" => 1, "data" => $data)));
		}
		
		die(json_encode(array("result" => 0)));
	}






	public function getCartTotal() {
		global $_W;
		$cartotal = pdo_fetchcolumn("select sum(total) from " . tablename('shopping_cart') . " where weid = '{$_W['uniacid']}' and from_user='{$_W['fans']['from_user']}'");
		return empty($cartotal) ? 0 : $cartotal;
	}
	private function getFeedbackType($type) {
		$types = array(1 => '维权', 2 => '告警');
		return $types[intval($type)];
	}
	private function getFeedbackStatus($status) {
		$statuses = array('未解决', '用户同意', '用户拒绝');
		return $statuses[intval($status)];
	}
	public function doMobilelist() {
		global $_GPC, $_W;
	
		$pindex = max(1, intval($_GPC['page']));
		$psize = 4;
		$condition = '';
		if (!empty($_GPC['ccate'])) {
			$cid = intval($_GPC['ccate']);
			$condition .= " AND ccate = '{$cid}'";
			$_GPC['pcate'] = pdo_fetchcolumn("SELECT parentid FROM " . tablename('shopping_category') . " WHERE id = :id", array(':id' => intval($_GPC['ccate'])));
		} elseif (!empty($_GPC['pcate'])) {
			$cid = intval($_GPC['pcate']);
			$condition .= " AND pcate = '{$cid}'";
		}
		if (!empty($_GPC['keyword'])) {
			$condition .= " AND title LIKE '%{$_GPC['keyword']}%'";
		}
		$children = array();
		$category = pdo_fetchall("SELECT * FROM " . tablename('shopping_category') . " WHERE weid = '{$_W['uniacid']}' and enabled=1 ORDER BY parentid ASC, displayorder DESC", array(), 'id');
		foreach ($category as $index => $row) {
			if (!empty($row['parentid'])) {
				$children[$row['parentid']][$row['id']] = $row;
				unset($category[$index]);
			}
		}
		$recommandcategory = array();
		foreach ($category as &$c) {
			if ($c['isrecommand'] == 1) {
				$c['list'] = pdo_fetchall("SELECT * FROM " . tablename('shopping_goods') . " WHERE weid = '{$_W['uniacid']}' and deleted=0 AND status = '1'  and pcate='{$c['id']}'  ORDER BY displayorder DESC, sales DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
				$c['total'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_goods') . " WHERE weid = '{$_W['uniacid']}'  and deleted=0  AND status = '1' and pcate='{$c['id']}'");
				$c['pager'] = pagination($c['total'], $pindex, $psize, $url = '', $context = array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
				$recommandcategory[] = $c;
			}
			if (!empty($children[$c['id']])) {
				foreach ($children[$c['id']] as &$child) {
					if ($child['isrecommand'] == 1) {
						$child['list'] = pdo_fetchall("SELECT * FROM " . tablename('shopping_goods') . " WHERE weid = '{$_W['uniacid']}'  and deleted=0 AND status = '1'  and pcate='{$c['id']}' and ccate='{$child['id']}'  ORDER BY displayorder DESC, sales DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
						$child['total'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_goods') . " WHERE weid = '{$_W['uniacid']}'  and deleted=0  AND status = '1' and pcate='{$c['id']}' and ccate='{$child['id']}' ");
						$child['pager'] = pagination($child['total'], $pindex, $psize, $url = '', $context = array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
						$recommandcategory[] = $child;
					}
				}
				unset($child);
			}
		}
		unset($c);
		$carttotal = $this->getCartTotal();
		//幻灯片
		$advs = pdo_fetchall("select * from " . tablename('shopping_adv') . " where enabled=1 order by displayorder asc");
		foreach ($advs as &$adv) {
			if (substr($adv['link'], 0, 5) != 'http:') {
				$adv['link'] = "http://" . $adv['link'];
			}
		}
		unset($adv);
		//首页推荐
		$rpindex = max(1, intval($_GPC['rpage']));
		$rpsize = 4;
		$condition = ' and isrecommand=1';
		$rlist = pdo_fetchall("SELECT * FROM " . tablename('shopping_goods') . " WHERE weid = '{$_W['uniacid']}'  and deleted=0 AND status = '1' $condition ORDER BY displayorder DESC, sales DESC LIMIT " . ($rpindex - 1) * $rpsize . ',' . $rpsize);
       



       $antiquenews = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 1 ORDER BY id DESC");
       $this->assign('antiquenews',$antiquenews);
        
        //首页成功案例上拉分页
        global $_GPC, $_W;
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 6;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_order') . " WHERE status > 1 and isshow > 0");
		$orders = pdo_fetchall("SELECT * FROM " . tablename('shopping_order') . " WHERE status > 1 and isshow > 0 ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
        foreach($orders as $key => $val){
            $ava = pdo_fetch("SELECT * FROM " . tablename('mc_members') . " WHERE openid = :openid ", array(':openid' => $val['from_user']));
            $orders[$key]['nickname'] = cut_str($val['nickname'], 1, 0).'**';
            $orders[$key]['avatar'] = $ava['avatar'];
            $orders[$key]['upimg'] = unserialize($val['upimg'])[0];
        }
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){
            foreach($orders as $k => $ord){

               $orders[$k]['url'] = $this->createMobileUrl('case',array('id' => $ord['id']));
               $ava = pdo_fetch("SELECT avatar FROM " . tablename('mc_members') . " WHERE openid = :openid ", array(':openid' => $ord['from_user']));
               $orders[$k]['avatar'] = $ava['avatar'];
               $orders[$k]['nickname'] = cut_str($ord['nickname'], 1, 0).'**';
             //  $orders[$k]['upimg'] = unserialize($ord['upimg'])[0];
               $orders[$k]['createtime'] = date('m-d',$ord['createtime']);

               $orders[$k]['resonrel'] = $orders[$k]['resonrel']=="真"?'zhen':'jia';
            }
			return json_encode($orders);
			exit;
		}

        $this->assign('orders',$orders);
		include $this->template('list');
	}
	public function doMobilelistmore_rec() {
		global $_GPC, $_W;
		$pindex = max(1, intval($_GPC['page']));
		$psize = 4;
		$condition = ' and isrecommand=1 ';
		$list = pdo_fetchall("SELECT * FROM " . tablename('shopping_goods') . " WHERE weid = '{$_W['uniacid']}'  and deleted=0 AND status = '1' $condition ORDER BY displayorder DESC, sales DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
		include $this->template('list_more');
	}
	public function doMobilelistmore() {
		global $_GPC, $_W;
		$pindex = max(1, intval($_GPC['page']));
		$psize = 4;
		$condition = '';
		$params = array(':weid' => $_W['uniacid']);
		$cid = intval($_GPC['ccate']);
		if (empty($cid)) {
			return NULL;
		}

		$catePid = $_GPC['pcate'];
		if (empty($catePid)) {
			$condition .= ' AND `pcate` = :pcate';
			$params[':pcate'] = $cid;
		} else {
			$condition .= ' AND `ccate` = :ccate';
			$params[':ccate'] = $cid;
		}


		$sql = 'SELECT * FROM ' . tablename('shopping_goods') . ' WHERE `weid` = :weid AND `deleted` = :deleted AND `status` = :status ' . $condition .
				' ORDER BY `displayorder` DESC, `sales` DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
		$params[':deleted'] = 0;
		$params[':status'] = 1;
		$list = pdo_fetchall($sql, $params);

		include $this->template('list_more');

	}
	public function doMobilelist2() {
		global $_GPC, $_W;
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 10;
		$condition = '';
		if (!empty($_GPC['ccate'])) {
			$cid = intval($_GPC['ccate']);
			$condition .= " AND ccate = '{$cid}'";
			$_GPC['pcate'] = pdo_fetchcolumn("SELECT parentid FROM " . tablename('shopping_category') . " WHERE id = :id", array(':id' => intval($_GPC['ccate'])));
		} elseif (!empty($_GPC['pcate'])) {
			$cid = intval($_GPC['pcate']);
			$condition .= " AND pcate = '{$cid}'";
		}
		if (!empty($_GPC['keyword'])) {
			$condition .= " AND title LIKE '%{$_GPC['keyword']}%'";
		}
		$sort = empty($_GPC['sort']) ? 0 : $_GPC['sort'];
		$sortfield = "displayorder asc";
		$sortb0 = empty($_GPC['sortb0']) ? "desc" : $_GPC['sortb0'];
		$sortb1 = empty($_GPC['sortb1']) ? "desc" : $_GPC['sortb1'];
		$sortb2 = empty($_GPC['sortb2']) ? "desc" : $_GPC['sortb2'];
		$sortb3 = empty($_GPC['sortb3']) ? "asc" : $_GPC['sortb3'];
		if ($sort == 0) {
			$sortb00 = $sortb0 == "desc" ? "asc" : "desc";
			$sortfield = "createtime " . $sortb0;
			$sortb11 = "desc";
			$sortb22 = "desc";
			$sortb33 = "asc";
		} else if ($sort == 1) {
			$sortb11 = $sortb1 == "desc" ? "asc" : "desc";
			$sortfield = "sales " . $sortb1;
			$sortb00 = "desc";
			$sortb22 = "desc";
			$sortb33 = "asc";
		} else if ($sort == 2) {
			$sortb22 = $sortb2 == "desc" ? "asc" : "desc";
			$sortfield = "viewcount " . $sortb2;
			$sortb00 = "desc";
			$sortb11 = "desc";
			$sortb33 = "asc";
		} else if ($sort == 3) {
			$sortb33 = $sortb3 == "asc" ? "desc" : "asc";
			$sortfield = "marketprice " . $sortb3;
			$sortb00 = "desc";
			$sortb11 = "desc";
			$sortb22 = "desc";
		}
		$sorturl = $this->createMobileUrl('list2', array("keyword" => $_GPC['keyword'], "pcate" => $_GPC['pcate'], "ccate" => $_GPC['ccate']), true);
		if (!empty($_GPC['isnew'])) {
			$condition .= " AND isnew = 1";
			$sorturl.="&isnew=1";
		}
		if (!empty($_GPC['ishot'])) {
			$condition .= " AND ishot = 1";
			$sorturl.="&ishot=1";
		}
		if (!empty($_GPC['isdiscount'])) {
			$condition .= " AND isdiscount = 1";
			$sorturl.="&isdiscount=1";
		}
		if (!empty($_GPC['istime'])) {
			$condition .= " AND istime = 1 and " . time() . ">=timestart and " . time() . "<=timeend";
			$sorturl.="&istime=1";
		}
		$children = array();
		$category = pdo_fetchall("SELECT * FROM " . tablename('shopping_category') . " WHERE weid = '{$_W['uniacid']}' and enabled=1 ORDER BY parentid ASC, displayorder DESC", array(), 'id');
		foreach ($category as $index => $row) {
			if (!empty($row['parentid'])) {
				$children[$row['parentid']][$row['id']] = $row;
				unset($category[$index]);
			}
		}
		$list = pdo_fetchall("SELECT * FROM " . tablename('shopping_goods') . " WHERE weid = '{$_W['uniacid']}'  and deleted=0 AND status = '1' $condition ORDER BY $sortfield LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
		foreach ($list as &$r) {
			if ($r['istime'] == 1) {
				$arr = $this->time_tran($r['timeend']);
				$r['timelaststr'] = $arr[0];
				$r['timelast'] = $arr[1];
			}
		}
		unset($r);
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_goods') . " WHERE weid = '{$_W['uniacid']}'  and deleted=0  AND status = '1' $condition");
		$pager = pagination($total, $pindex, $psize, $url = '', $context = array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
		$carttotal = $this->getCartTotal();
		include $this->template('list2');
	}
	function time_tran($the_time) {
		$timediff = $the_time - time();
		$days = intval($timediff / 86400);
		if (strlen($days) <= 1) {
			$days = "0" . $days;
		}
		$remain = $timediff % 86400;
		$hours = intval($remain / 3600);
		;
		if (strlen($hours) <= 1) {
			$hours = "0" . $hours;
		}
		$remain = $remain % 3600;
		$mins = intval($remain / 60);
		if (strlen($mins) <= 1) {
			$mins = "0" . $mins;
		}
		$secs = $remain % 60;
		if (strlen($secs) <= 1) {
			$secs = "0" . $secs;
		}
		$ret = "";
		if ($days > 0) {
			$ret.=$days . " 天 ";
		}
		if ($hours > 0) {
			$ret.=$hours . ":";
		}
		if ($mins > 0) {
			$ret.=$mins . ":";
		}
		$ret.=$secs;
		return array("倒计时 " . $ret, $timediff);
	}
	public function doMobileMyCart() {
		global $_W, $_GPC;
		$this->checkAuth();
		$op = $_GPC['op'];
		if ($op == 'add') {
			$goodsid = intval($_GPC['id']);
			$total = intval($_GPC['total']);
			$total = empty($total) ? 1 : $total;
			$optionid = intval($_GPC['optionid']);
			$goods = pdo_fetch("SELECT id, type, total,marketprice,maxbuy FROM " . tablename('shopping_goods') . " WHERE id = :id", array(':id' => $goodsid));
			if (empty($goods)) {
				$result['message'] = '抱歉，该专家不存在或是已经被删除！';
				message($result, '', 'ajax');
			}
			$marketprice = $goods['marketprice'];
			if (!empty($optionid)) {
				$option = pdo_fetch("select marketprice from " . tablename('shopping_goods_option') . " where id=:id limit 1", array(":id" => $optionid));
				if (!empty($option)) {
					$marketprice = $option['marketprice'];
				}
			}
			$row = pdo_fetch("SELECT id, total FROM " . tablename('shopping_cart') . " WHERE from_user = :from_user AND weid = '{$_W['uniacid']}' AND goodsid = :goodsid  and optionid=:optionid", array(':from_user' => $_W['fans']['from_user'], ':goodsid' => $goodsid,':optionid'=>$optionid));
			if ($row == false) {
				//不存在
				$data = array(
					'weid' => $_W['uniacid'],
					'goodsid' => $goodsid,
					'goodstype' => $goods['type'],
					'marketprice' => $marketprice,
					'from_user' => $_W['fans']['from_user'],
					'total' => $total,
					'optionid' => $optionid
				);
				pdo_insert('shopping_cart', $data);
			} else {
				//累加最多限制购买数量
				$t = $total + $row['total'];
				if (!empty($goods['maxbuy'])) {
					if ($t > $goods['maxbuy']) {
						$t = $goods['maxbuy'];
					}
				}
				//存在
				$data = array(
					'marketprice' => $marketprice,
					'total' => $t,
					'optionid' => $optionid
				);
				pdo_update('shopping_cart', $data, array('id' => $row['id']));
			}
			//返回数据
			$carttotal = $this->getCartTotal();
			$result = array(
				'result' => 1,
				'total' => $carttotal
			);
			die(json_encode($result));
		} else if ($op == 'clear') {
			pdo_delete('shopping_cart', array('from_user' => $_W['fans']['from_user'], 'weid' => $_W['uniacid']));
			die(json_encode(array("result" => 1)));
		} else if ($op == 'remove') {
			$id = intval($_GPC['id']);
			pdo_delete('shopping_cart', array('from_user' => $_W['fans']['from_user'], 'weid' => $_W['uniacid'], 'id' => $id));
			die(json_encode(array("result" => 1, "cartid" => $id)));
		} else if ($op == 'update') {
			$id = intval($_GPC['id']);
			$num = intval($_GPC['num']);
			$sql = "update " . tablename('shopping_cart') . " set total=$num where id=:id";
			pdo_query($sql, array(":id" => $id));
			die(json_encode(array("result" => 1)));
		} else {
			$list = pdo_fetchall("SELECT * FROM " . tablename('shopping_cart') . " WHERE  weid = '{$_W['uniacid']}' AND from_user = '{$_W['fans']['from_user']}'");
			$totalprice = 0;
			if (!empty($list)) {
				foreach ($list as &$item) {
					$goods = pdo_fetch("SELECT  title, thumb, marketprice, unit, total,maxbuy FROM " . tablename('shopping_goods') . " WHERE id=:id limit 1", array(":id" => $item['goodsid']));
					//属性
					$option = pdo_fetch("select title,marketprice,stock from " . tablename("shopping_goods_option") . " where id=:id limit 1", array(":id" => $item['optionid']));
					if ($option) {
						$goods['title'] = $goods['title'];
						$goods['optionname'] = $option['title'];
						$goods['marketprice'] = $option['marketprice'];
						$goods['total'] = $option['stock'];
					}
					$item['goods'] = $goods;
					$item['totalprice'] = (floatval($goods['marketprice']) * intval($item['total']));
					$totalprice += $item['totalprice'];
				}
				unset($item);
			}
			include $this->template('cart');
		}
	}
	public function doMobileConfirm() {
		global $_W, $_GPC;
		$this->checkauth();
		$totalprice = 0;
		$allgoods = array();
		$id = intval($_GPC['id']);
		$optionid = intval($_GPC['optionid']);
		$total = intval($_GPC['total']);
		if ( (empty($total)) || ($total < 1) ) {
			$total = 1;
		}
		$direct = false; //是否是直接购买
		$returnUrl = ''; //当前连接
		if (!empty($id)) {
			$sql = 'SELECT `id`, `thumb`, `title`, `weight`, `marketprice`, `total`, `type`, `totalcnf`, `sales`, `unit`, `istime`, `timeend`, `usermaxbuy`
					FROM ' .tablename('shopping_goods') . ' WHERE `id` = :id';
			$item = pdo_fetch($sql, array(':id' => $id));

			if (empty($item)) {
				message('专家不存在或已经下架', $this->createMobileUrl('detail', array('id' => $id)), 'error');
			}
			if ($item['istime'] == 1) {
				if (time() > $item['timeend']) {
					$backUrl = $this->createMobileUrl('detail', array('id' => $id));
					$backUrl = $_W['siteroot'] . 'app' . ltrim($backUrl, '.');
					message('抱歉，专家限购时间已到，无法购买了！', $backUrl, "error");
				}
			}
			if ($item['total'] - $total < 0) {
				message('抱歉，[' . $item['title'] . ']库存不足！', $this->createMobileUrl('confirm'), 'error');
			}

			if (!empty($optionid)) {
				$option = pdo_fetch("select title,marketprice,weight,stock from " . tablename("shopping_goods_option") . " where id=:id limit 1", array(":id" => $optionid));
				if ($option) {
					$item['optionid'] = $optionid;
					$item['title'] = $item['title'];
					$item['optionname'] = $option['title'];
					$item['marketprice'] = $option['marketprice'];
					$item['weight'] = $option['weight'];
				}
			}
			$item['stock'] = $item['total'];
			$item['total'] = $total;
			$item['totalprice'] = $total * $item['marketprice'];
			$allgoods[] = $item;
			$totalprice += $item['totalprice'];
			if ($item['type'] == 1) {
				$needdispatch = true;
			}
			$direct = true;

			// 检查用户最多购买数量
			$sql = 'SELECT SUM(`og`.`total`) AS `orderTotal` FROM ' . tablename('shopping_order_goods') . ' AS `og` JOIN ' . tablename('shopping_order') .
				' AS `o` ON `og`.`orderid` = `o`.`id` WHERE `og`.`goodsid` = :goodsid AND `o`.`from_user` = :from_user';
			$params = array(':goodsid' => $id, ':from_user' => $_W['fans']['from_user']);
			$orderTotal = pdo_fetchcolumn($sql, $params);
			if ( (($orderTotal + $item['total']) > $item['usermaxbuy']) && (!empty($item['usermaxbuy']))) {
				message('您已经超过购买数量了', $this->createMobileUrl('detail', array('id' => $id)), 'error');
			}

			$returnUrl = urlencode($_W['siteurl']);
		}
		if (!$direct) {
			//如果不是直接购买（从购物车购买）
			$goodids = $_GPC['goodids'];
			$condition =  empty($goodids) ? '' : 'AND id IN ('.$goodids.")";
			$list = pdo_fetchall("SELECT * FROM " . tablename('shopping_cart') . " WHERE  weid = '{$_W['uniacid']}' AND from_user = '{$_W['fans']['from_user']}' {$condition}");
			if (!empty($list)) {
				foreach ($list as &$g) {
					$item = pdo_fetch("select id,thumb,title,weight,marketprice,total,type,totalcnf,sales,unit from " . tablename("shopping_goods") . " where id=:id limit 1", array(":id" => $g['goodsid']));
					//属性
					$option = pdo_fetch("select title,marketprice,weight,stock from " . tablename("shopping_goods_option") . " where id=:id limit 1", array(":id" => $g['optionid']));
					if ($option) {
						$item['optionid'] = $g['optionid'];
						$item['title'] = $item['title'];
						$item['optionname'] = $option['title'];
						$item['marketprice'] = $option['marketprice'];
						$item['weight'] = $option['weight'];
					}
					$item['stock'] = $item['total'];
					$item['total'] = $g['total'];
					$item['totalprice'] = $g['total'] * $item['marketprice'];
					$allgoods[] = $item;
					$totalprice += $item['totalprice'];
					if ($item['type'] == 1) {
						$needdispatch = true;
					}
				}
				unset($g);
			}
			$returnUrl = $this->createMobileUrl("confirm");
		}
		if (count($allgoods) <= 0) {
			header("location: " . $this->createMobileUrl('myorder'));
			exit();
		}

		//配送方式
		$dispatch = pdo_fetchall("select id,dispatchname,dispatchtype,firstprice,firstweight,secondprice,secondweight from " . tablename("shopping_dispatch") . " WHERE weid = {$_W['uniacid']} order by displayorder desc");
		foreach ($dispatch as &$d) {
			$weight = 0;
			foreach ($allgoods as $g) {
				$weight += $g['weight'] * $g['total'];
			}
			$price = 0;
			if ($weight <= $d['firstweight']) {
				$price = $d['firstprice'];
			} else {
				$price = $d['firstprice'];
				$secondweight = $weight - $d['firstweight'];
				if ($secondweight % $d['secondweight'] == 0) {
					$price += (int)($secondweight / $d['secondweight']) * $d['secondprice'];
				} else {
					$price += (int)($secondweight / $d['secondweight'] + 1) * $d['secondprice'];
				}
			}
			$d['price'] = $price;
		}
		unset($d);

		if (checksubmit('submit')) {
			// 是否自提
			$sendtype = 1;
                $address = pdo_fetch("SELECT * FROM " . tablename('mc_member_address') . " WHERE id = :id", array(':id' => intval($_GPC['address'])));
            if ($_GPC['goodstype'] != '2') {
                if (empty($address)) {
                    message('抱歉，请您填写收货地址！');
                }
                // 运费
                $dispatchid = intval($_GPC['dispatch']);
                $dispatchprice = 0;
                foreach ($dispatch as $d) {
                    if ($d['id'] == $dispatchid) {
                        $dispatchprice = $d['price'];
                        $sendtype = $d['dispatchtype'];
                    }
                }
            } else {
                $sendtype = '3 ';
            }
            // 专家价格
            $goodsprice = 0;
            foreach ($allgoods as $row) {
                $goodsprice += $row['totalprice'];
            }

			$data = array(
				'weid' => $_W['uniacid'],
				'from_user' => $_W['fans']['from_user'],
				'ordersn' => date('md') . random(4, 1),
				'price' => $goodsprice + $dispatchprice,
				'dispatchprice' => $dispatchprice,
				'goodsprice' => $goodsprice,
				'status' => 0,
				'sendtype' => intval($sendtype),
				'dispatch' => $dispatchid,
				'goodstype' => intval($item['type']),
				'remark' => $_GPC['remark'],
				'address' =>  $address['username'] . '|' . $address['mobile'] . '|' . $address['zipcode']
							. '|' . $address['province'] . '|' . $address['city'] . '|' .
							$address['district'] . '|' . $address['address'],
				'createtime' => TIMESTAMP
			);
			pdo_insert('shopping_order', $data);
			$orderid = pdo_insertid();
			//插入订单专家
			foreach ($allgoods as $row) {
				if (empty($row)) {
					continue;
				}
				$d = array(
					'weid' => $_W['uniacid'],
					'goodsid' => $row['id'],
					'orderid' => $orderid,
					'total' => $row['total'],
					'price' => $row['marketprice'],
					'createtime' => TIMESTAMP,
					'optionid' => $row['optionid']
				);
				$o = pdo_fetch("select title from " . tablename('shopping_goods_option') . " where id=:id limit 1", array(":id" => $row['optionid']));
				if (!empty($o)) {
					$d['optionname'] = $o['title'];
				}
				pdo_insert('shopping_order_goods', $d);
			}
			// 清空购物车
			if (!$direct) {
				pdo_delete("shopping_cart", array("weid" => $_W['uniacid'], "from_user" => $_W['fans']['from_user']));
			}
			// 变更专家库存
			if (empty($item['totalcnf'])) {
				$this->setOrderStock($orderid);
			}
			message('提交订单成功,现在跳转到付款页面...', $this->createMobileUrl('pay', array('orderid' => $orderid)), 'success');
		}
		$carttotal = $this->getCartTotal();
		$profile = fans_search($_W['fans']['from_user'], array('resideprovince', 'residecity', 'residedist', 'address', 'realname', 'mobile'));
		$row = pdo_fetch("SELECT * FROM " . tablename('mc_member_address') . " WHERE isdefault = 1 and uid = :uid limit 1", array(':uid' => $_W['member']['uid']));
		include $this->template('confirm');
	}

	//设置订单积分
	public function setOrderCredit($orderid, $add = true) {
		global $_W;
		$order = pdo_fetch("SELECT * FROM " . tablename('shopping_order') . " WHERE id = :id AND weid = :weid  limit 1", array(':id' => $orderid, ':weid' => $_W['uniacid']));
		if (empty($order)) {
			return false;
		}
		$sql = 'SELECT `goodsid`, `total` FROM ' . tablename('shopping_order_goods') . ' WHERE `orderid` = :orderid';
		$orderGoods = pdo_fetchall($sql, array(':orderid' => $orderid));
		if (!empty($orderGoods)) {
			$credit = 0.00;
			$sql = 'SELECT `credit` FROM ' . tablename('shopping_goods') . ' WHERE `id` = :id';
			foreach ($orderGoods as $goods) {
				$goodsCredit = pdo_fetchcolumn($sql, array(':id' => $goods['goodsid']));
				$credit += $goodsCredit * floatval($goods['total']);
			}
		}
		//增加积分
		if (!empty($credit)) {
			load()->model('mc');
			load()->func('compat.biz');
			$uid = mc_openid2uid($order['from_user']);
			$fans = fans_search($uid, array("credit1"));
			if (!empty($fans)) {
				if (!empty($add)) {
					mc_credit_update($_W['member']['uid'], 'credit1', $credit, array('0' => $_W['member']['uid'], '购买专家赠送'));
				} else {
					mc_credit_update($_W['member']['uid'], 'credit1', 0 - $credit, array('0' => $_W['member']['uid'], '微商城操作'));
				}
			}
		}
	}
	public function doMobilePay() {
		global $_W, $_GPC;
		$this->checkAuth();
		$orderid = intval($_GPC['orderid']);
		$order = pdo_fetch("SELECT * FROM " . tablename('shopping_order') . " WHERE id = :id AND weid = :weid", array(':id' => $orderid, ':weid' => $_W['uniacid']));
		if ($order['status'] != '0') {
			message('抱歉，您的订单已经付款或是被关闭，请重新进入付款！', $this->createMobileUrl('myorder'), 'error');
		}
		if (checksubmit('codsubmit')) {
			$ordergoods = pdo_fetchall("SELECT goodsid, total,optionid FROM " . tablename('shopping_order_goods') . " WHERE orderid = '{$orderid}'", array(), 'goodsid');
			if (!empty($ordergoods)) {
				$goods = pdo_fetchall("SELECT id, title, thumb, marketprice, unit, total,credit FROM " . tablename('shopping_goods') . " WHERE id IN ('" . implode("','", array_keys($ordergoods)) . "')");
			}
			//邮件提醒
			if (!empty($this->module['config']['noticeemail'])) {
//				$address = pdo_fetch("SELECT * FROM " . tablename('mc_member_address') . " WHERE id = :id", array(':id' => $order['addressid']));
				$address = explode('|', $order['address']);
				$body = "<h3>购买专家清单</h3> <br />";
				if (!empty($goods)) {
					foreach ($goods as $row) {
						//属性
						$option = pdo_fetch("select title,marketprice,weight,stock from " . tablename("shopping_goods_option") . " where id=:id limit 1", array(":id" => $ordergoods[$row['id']]['optionid']));
						if ($option) {
							$row['title'] = "[" . $option['title'] . "]" . $row['title'];
						}
						$body .= "名称：{$row['title']} ，数量：{$ordergoods[$row['id']]['total']} <br />";
					}
				}
				$paytype = $order['paytype']=='3'?'货到付款':'已付款';
				$body .= "<br />总金额：{$order['price']}元 （{$paytype}）<br />";
				$body .= "<h3>购买用户详情</h3> <br />";
				$body .= "真实姓名：$address[0] <br />";
				$body .= "地区：$address[3] - $address[4] - $address[5]<br />";
				$body .= "详细地址：$address[6] <br />";
				$body .= "手机：$address[1] <br />";
				load()->func('communication');
				ihttp_email($this->module['config']['noticeemail'], '微商城订单提醒', $body);
			}
			pdo_update('shopping_order', array('status' => '1', 'paytype' => '3'), array('id' => $orderid, 'uniacid' => $_W['uniacid']));
			message('订单提交成功，请您收到货时付款！', $this->createMobileUrl('myorder'), 'success');
		}
		if (checksubmit()) {
			if ($order['paytype'] == 1 && $_W['fans']['credit2'] < $order['price']) {
				message('抱歉，您帐户的余额不够支付该订单，请充值！', create_url('mobile/module/charge', array('name' => 'member', 'weid' => $_W['uniacid'])), 'error');
			}
			if ($order['price'] == '0') {
				$this->payResult(array('tid' => $orderid, 'from' => 'return', 'type' => 'credit2'));
				exit;
			}
		}
		// 专家编号
		$sql = 'SELECT `goodsid` FROM ' . tablename('shopping_order_goods') . " WHERE `orderid` = :orderid";
		$goodsId = pdo_fetchcolumn($sql, array(':orderid' => $orderid));
		// 专家名称
		$sql = 'SELECT `title` FROM ' . tablename('shopping_goods') . " WHERE `id` = :id";
		$goodsTitle = pdo_fetchcolumn($sql, array(':id' => $goodsId));

		$params['tid'] = $orderid;
		$params['user'] = $_W['fans']['from_user'];
		$params['fee'] = $order['price'];
		$params['title'] = $goodsTitle;
		$params['ordersn'] = $order['ordersn'];
		$params['virtual'] = $order['goodstype'] == 2 ? true : false;

		include $this->template('pay');
	}

	public function doMobileContactUs() {
		global $_W;
		$cfg = $this->module['config'];
		include $this->template('contactus');
	}
    public function doMobileRegister(){
        global $_W;
            $openid = $_W['openid'];
            $avatar = $_W['fans']['tag']['avatar'];
            $nickname = $_W['fans']['tag']['nickname'];
            $phone = $_POST['phone'];
            $code = $_POST['code'];
            $zcode = $_SESSION['zcode'];
            if(($zcode == $code)&&($code!='')){
                $user = pdo_fetchall("SELECT * FROM " . tablename('shopping_goods') . " WHERE phone = :phone ", array(':phone' => $phone));
                if($user){
                    $zhuanjia = pdo_fetchall("SELECT * FROM " . tablename('shopping_goods') . " WHERE openid = :openid ", array(':openid' => $openid));
                    if(empty($zhuanjia)){
                        pdo_query("update " . tablename('shopping_goods') . " set openid = :openid, nickname = :nickname where phone=:phone ", 
                                array(':phone' => $phone, ':openid' => $openid, ':nickname' => $nickname));
                        $user['mark'] = 1;
                        $this->assign('user',$user);
                        message('专家手机号绑定成功！', $this->createMobileUrl('member', array('mark' => 1)), 'success');
                    }else{
                        message('专家已绑定，无需再次绑定！');
                    }
                    
                }else{
                    $huiyuan = pdo_fetchall("SELECT * FROM " . tablename('mc_members') . " WHERE openid = :openid ", array(':openid' => $openid));
                    if(empty($huiyuan)){
                        $data = array(
                            'openid' => $_W['openid'],
                            'mobile' => $phone,
                            'avatar' => $avatar,
                            'nickname' => $nickname,
                            'createtime' => TIMESTAMP
                        );
                        pdo_insert('mc_members', $data); 
                        $this->assign('user',$data);
                        sendtext($phone,1,0,0);
                        if($_GET['done']){
                            message('注册会员成功！', $this->createMobileUrl('jianbaoxieyi', array('mark' => 0)), 'success');
                        }else{
                            message('注册会员成功！', $this->createMobileUrl('member', array('mark' => 0)), 'success');
                        }
                    }else{
                        message('会员已注册，无需再次注册！');
                    }
                }  
            }else{
                message('验证码有误，请重新获取！');
            }
         
    }
    
        //短信验证码
    public function doMobileGetCode(){
        $content = makecode();
        $phone = $_POST["phone"];
        $test = sendSMS($phone,$content);
        $_SESSION['zcode'] = $content;
        if($test){
            $sign = 1;
        }else{
            $sign = 0;
        }
        die(json_encode(array('sign' => $sign)));
        exit;
    }

    
    public function doMobileCategory() {
        $category = pdo_fetchall("SELECT * FROM ".tablename('shopping_category')." WHERE weid < 2 ORDER BY id ASC");
        $cate = $_GET['cate'];
        if($cate==1){
        //    $category = $category[0];
            include $this->template('category',array('cate'=>1));
        }elseif($cate==2){
         //   $category = $category[1];
            $this->assign('category',$category);
            include $this->template('category',array('cate'=>2));
        }elseif($cate==3){
        //    $category = $category[2];
            $this->assign('category',$category);
            include $this->template('category',array('cate'=>3));
        }elseif($cate==4){
        //    $category = $category[3];
            $this->assign('category',$category);
            include $this->template('category',array('cate'=>4));
        }elseif($cate==5){
        //    $category = $category[4];
            $this->assign('category',$category);
            include $this->template('category',array('cate'=>5));
        }
    }

    public function doMobileCase() {
        global $_GPC, $_W;
        $title = "案例";
        $jieshu = $_GET['jieshu'];
        $order = pdo_fetchall("SELECT * FROM ".tablename('shopping_order')." WHERE id ORDER BY id DESC");
        $id = $_GET['id'];
		$act = trim($_GPC['act']);

		if($act == 'src'){
			$goodid= $_GPC['goodid'];
			$collect =  pdo_fetch("SELECT * FROM ".tablename('shopping_goods_collect')." WHERE openid = :openid and goodid = :goodid", array('openid'=>$_W['openid'],'goodid'=>$goodid));
			$total = pdo_fetchcolumn("select count(*) from " .tablename("shopping_goods_collect")." where goodid=".$goodid);
			if($collect){
				$datacollect = array();
				$shopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$goodid));
				$total -=1;
				pdo_update("shopping_goods", array('collect'=>$shopclass['collect']), array("id" => $goodid));
				
				pdo_delete('shopping_goods_collect', array('id'=>$collect['id']));
				$datacollect['status'] = 1;
				$datacollect['num']  = $total;
				die(json_encode($datacollect));
			}else{
				$datacollect = array();
				$shopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$goodid));
				//var_dump($shopclass);
				if(($shopclass['goodid']==$goodid) && ($shopclass['openid']==$_W['openid'])){
					pdo_delete('shopping_goods_collect', array('id'=>$collect['id']));
					$total -=1;
					$datacollect['status'] = 1;
					$datacollect['num']  = $total;
					die(json_encode($datacollect));
				}else{

					$total +=1;
					pdo_update("shopping_goods", array('collect'=>$shopclass['collect']), array("id" => $goodid));
					$data['goodid'] = $goodid;
					$data['openid'] = $_W['openid'];
					$data['created_at'] = time();
					pdo_insert('shopping_goods_collect', $data);
					$datacollect['status'] = 2;
					$datacollect['num']  = $total;
					die(json_encode($datacollect));
				}
			}
		}
        $this->assign('order',$order);
		
		$neworder = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id  ORDER BY id DESC",array('id'=>$id));

		$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE  `isuser` = 0 and id <> :id ", array('id'=>$neworder['expert'],'openid'=>$_W['openid']));
			
	
	if(!empty($zhuanjia)){
		$iszhuanjia = 1;
	}else{
		$iszhuanjia = 0;
	}
		
        if($id){
            if($_GET['yidu']){
                pdo_update('shopping_certificate', array('yidu' => 1), array('orderid' => $id));
            }
            if($_GET['yjd'])
            {
            	pdo_update('shopping_order', array('yjd' => 1), array('id' => $id));
            }
            if($_GET['zjyjd'])
            {
            	pdo_update('shopping_order', array('zjyjd' => 1), array('id' => $id));
            }
            $orderimgs = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = ".$id);
            pdo_query("update " . tablename('shopping_order') . " set shownum=shownum+1 where id=:id ", array(":id" => $id));
            $orderimg = unserialize($orderimgs['upimg']);
            $order = $orderimgs;
            $order['nickname'] = cut_str($order['nickname'], 1, 0).'**';
            $item = pdo_fetchall("SELECT * FROM ".tablename('shopping_order')." WHERE id =:id",array(":id" => $id));
            $item = $item[0];
            $user = pdo_fetchall("SELECT * FROM ".tablename('mc_members')." WHERE openid =:openid",array(":openid" => $item['from_user']));
            $avatar = $user[0]['avatar'];
            //专家信息
            $openid = $item['zjopenid'];
            $expert = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid =:openid",array(":openid" => $openid));
            $category = pdo_fetch("SELECT * FROM ".tablename('shopping_category')." WHERE id =:id",array(":id" => $expert['pcate']));
            $expert['pcate'] = $category['name'];
            $comment = pdo_fetch("SELECT * FROM ".tablename('shopping_comment')." WHERE orderid =:orderid AND shows = '1'", array(":orderid" => $id));
			$voice = pdo_fetch("SELECT * FROM ".tablename('shopping_order_voice')." WHERE orderid = :id", array(":id" =>$id));
            if($_W['ispost']){
                $act = trim($_GPC['act']);
                $id = trim($_GPC['id']);
                if($act == 'listen_num'){
                    $voice = pdo_fetch("SELECT * FROM ".tablename('shopping_order_voice')." WHERE id = :id", array(":id" =>$id));
                    $listen_num = $voice['listen_num'] + 1;
                    pdo_update('shopping_order_voice', array('listen_num' => $listen_num), array('id' => $id));
                    $voice = pdo_fetch("SELECT * FROM ".tablename('shopping_order_voice')." WHERE id = :id", array(":id" =>$id));
                    die(json_encode($voice));
                }
                if($act == 'collect'){
                    $voice = pdo_fetch("SELECT * FROM ".tablename('shopping_order_voice')." WHERE id = :id", array(":id" =>$id));
                    $orderid = $voice['orderid'];
                    $alreadycollect = pdo_fetch("SELECT * FROM ".tablename('shopping_order_voice_collect')." WHERE orderid = :orderid and useropenid = :useropenid ", array(":orderid" =>$orderid, "useropenid" =>$_W['openid']));
                    if($alreadycollect){
                        $collect = $voice['collect'] - 1;
                        pdo_delete('shopping_order_voice_collect', array('id' => $alreadycollect['id']));
                        pdo_update('shopping_order_voice', array('collect' => $collect), array('id' => $id));
                        $voice = pdo_fetch("SELECT * FROM ".tablename('shopping_order_voice')." WHERE id = :id", array(":id" =>$id));
                        $voice['tu'] = 'Z_flt';
                    }else{
                        $collect = $voice['collect'] + 1;
                        pdo_insert('shopping_order_voice_collect', array('orderid' => $orderid, 'useropenid' => $_W['openid']));
                        pdo_update('shopping_order_voice', array('collect' => $collect), array('id' => $id));
                        $voice = pdo_fetch("SELECT * FROM ".tablename('shopping_order_voice')." WHERE id = :id", array(":id" =>$id));
                        $voice['tu'] = 'Z_flta';
                    }
                    
                    die(json_encode($voice));
                }
            }
            $goodscollect = pdo_fetchall("select openid from ".tablename('shopping_goods_collect')." where goodid=".$expert['id']);
            //var_dump($goodscollect);
            foreach ($goodscollect as $key => $value) 
            {
            	if($value['openid']==$_W['openid']){
            		$havecollect=1;
            	}
            }
            //var_dump($havecollect);
            $certificate = pdo_fetch("SELECT * FROM ".tablename('shopping_certificate')." WHERE orderid = :id", array(":id" =>$id));
            include $this->template('case_content',array('id'=>$id));
        }
    }
    
    
    
    public function doMobileAntiqueNewsList() {
        //分页
    /*    $page = isset($_GET['page'])?intval($_GET['page']):1;
        $nextpage = $page + 1;
        //每页显示10条数据
        $num = 10;   
        $allnews = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 1 ORDER BY id DESC");
        $total = count($allnews);
        $pagenum=ceil($total/$num);
        if($page>$pagenum || $page == 0){
            echo "没有更多了...";
            exit;
        }
        //获取limit的第一个参数的值 offset
        $offset=($page-1)*$num;   
        $news = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 1 ORDER BY id DESC LIMIT $offset,$num");
      //  return json_encode($news);
   */   
        //鉴宝资讯上拉分页
        global $_GPC, $_W;
         $title = "资讯";
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 6;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 1 ORDER BY id DESC");
		$news = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 1 ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
        $pager = pagination($total, $pindex, $psize);

		if($_W['ispost']){
            foreach($news as $k => $new){
                $news[$k]['url'] = $this->createMobileUrl('antiquenews',array('id'=>$new['id']));
                $len = strlen($new['title'])/3;
                if($len >10){
                    $news[$k]['title'] = mb_substr($new['title'],0,10,'utf-8')."...";
                }
                $news[$k]['createtime'] = date('Y-m-d',$new['createtime']);
                $lens = strlen($new['content'])/3;
                if($lens >30){
                    $news[$k]['content'] = mb_substr($new['content'],0,48,'utf-8')."...";
                }
            }
			return json_encode($news);
			exit;
		}
        $this->assign('news',$news);
        include $this->template('antiquenewslist');
    }
    public function doMobileAntiqueNews() {
    	global $_GPC, $_W;
        $title = "资讯";
        $go = $_GET['go'];
        $antiquenews = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 1 ORDER BY id DESC");
        $last = count($antiquenews) - 1;
        $this->assign('last',$last);
        $this->assign('antiquenews',$antiquenews);
        if($go){
            if($go == 1){
                $key = $_GET['key'] - 1;
                $before = $key - 1;
                $next = $key + 1;
                $this->assign('key',$key);
                $this->assign('before',$before);
                $this->assign('next',$next);
                $this->assign('antiquenews',$antiquenews);
            }
            if($go == 2){
                $key = $_GET['key']+1;
                $before = $key - 1;
                $next = $key + 1;
                $this->assign('key',$key);
                $this->assign('before',$before);
                $this->assign('next',$next);
                $this->assign('antiquenews',$antiquenews);
            }
            include $this->template('antiquenews');
        }else{
            foreach($antiquenews as $key => $news){
                if($_GET['id']==$news['id']){
                    $keys = $key;
                    break;
                }
            }
            $next = $key + 1;
            $before = $key - 1;
            $this->assign('key',$keys);
            $this->assign('before',$before);
            $this->assign('next',$next);
            $this->assign('antiquenews',$antiquenews);
            include $this->template('antiquenews');
           /* 直接跳内容页时使用该代码
            $key = 0;
            $next = $key + 1;
            $this->assign('key',$key);
            $this->assign('next',$next);
            $this->assign('antiquenews',$antiquenews);
            include $this->template('antiquenews');
            */
        }
	}
    public function doMobileNewsList() {
     
/*     //分页
        $page = isset($_GET['page'])?intval($_GET['page']):1;
        $nextpage = $page + 1;
        //每页显示10条数据
        $num = 10;   
        $allnews = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 2 ORDER BY id DESC");
        $total = count($allnews);
        $pagenum=ceil($total/$num);
        if($page>$pagenum || $page == 0){
            echo "没有更多了...";
            exit;
        }
        //获取limit的第一个参数的值 offset
        $offset=($page-1)*$num;   
        $news = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 2 ORDER BY id DESC LIMIT $offset,$num");
      //  return json_encode($news);
      */
        global $_GPC, $_W;
        $title = "资讯•活动";
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 6;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 2 ORDER BY id DESC");
		$news = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 2 ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){
            foreach($news as $k => $new){
                $news[$k]['url'] = $this->createMobileUrl('news',array('id'=>$new['id']));
                $len = strlen($new['title'])/3;
                if($len >10){
                    $news[$k]['title'] = mb_substr($new['title'],0,10,'utf-8')."...";
                }
                $news[$k]['createtime'] = date('Y-m-d',$new['createtime']);
                $lens = strlen($new['content'])/3;
                if($lens >30){
                    $news[$k]['content'] = mb_substr($new['content'],0,48,'utf-8')."...";
                }
            }
			return json_encode($news);
			exit;
		}
        $this->assign('news',$news);
        include $this->template('newslist');
    }
    public function doMobileNews() {
    	global $_GPC, $_W;
        $title = "资讯•活动";
        $go = $_GET['go'];
        $news = pdo_fetchall("SELECT * FROM " . tablename('imeepos_fvoice_news') . " WHERE id and class_id = 2 ORDER BY id DESC");
        $last = count($news) - 1;
        $this->assign('last',$last);
        $this->assign('news',$news);
        if($go){
            if($go == 1){
                $key = $_GET['key'] - 1;
                $before = $key - 1;
                $next = $key + 1;
                $this->assign('key',$key);
                $this->assign('before',$before);
                $this->assign('next',$next);
                $this->assign('news',$news);
            }
            if($go == 2){
                $key = $_GET['key']+1;
                $before = $key - 1;
                $next = $key + 1;
                $this->assign('key',$key);
                $this->assign('before',$before);
                $this->assign('next',$next);
                $this->assign('news',$news);
            }
            include $this->template('news');
        }else{
           foreach($news as $key => $new){
                if($_GET['id']==$new['id']){
                    $keys = $key;
                    break;
                }
            }
            $next = $key + 1;
            $before = $key - 1;
            $this->assign('key',$keys);
            $this->assign('before',$before);
            $this->assign('next',$next);
            $this->assign('news',$news);
            include $this->template('news');
        }
    }
	public function doMobileMyOrder() {
		global $_W, $_GPC;
		$smssetting = pdo_fetch("SELECT * FROM ".tablename('shopping_sendSMSsetting')." WHERE id =:id",array(":id" => 1));
		$kfphone = $smssetting['phone'];
		$op = $_GPC['op'];
		$openid = $_W['openid'];
        $login = trylogin($openid);
        if(is_array($login)){
            $user = trylogin($openid);
        }else{
            $user = 0;
        }
        if($user){
            $this->assign('user',$user);	
		if ($op == 'confirm') {
			$orderid = intval($_GPC['orderid']);
			$order = pdo_fetch("SELECT * FROM " . tablename('shopping_order') . " WHERE id = :id AND from_user = :from_user AND weid = :weid", array(':id' => $orderid, ':from_user' => $_W['fans']['from_user'], ':weid' => $_W['uniacid']));
			if (empty($order)) {
				message('抱歉，您的订单不存或是已经被取消！', $this->createMobileUrl('myorder'), 'error');
			}
			pdo_update('shopping_order', array('status' => 3), array('id' => $orderid, 'from_user' => $_W['fans']['from_user']));
			message('确认收货完成！', $this->createMobileUrl('myorder'), 'success');
		} else if ($op == 'detail') {
			$orderid = intval($_GPC['orderid']);
			$item = pdo_fetch("SELECT * FROM " . tablename('shopping_order') . " WHERE weid = '{$_W['uniacid']}' AND from_user = '{$_W['fans']['from_user']}' and id='{$orderid}' limit 1");
			if (empty($item)) {
				message('抱歉，您的订单不存或是已经被取消！', $this->createMobileUrl('myorder'), 'error');
			}
			$goodsid = pdo_fetch("SELECT goodsid,total FROM " . tablename('shopping_order_goods') . " WHERE orderid = '{$orderid}'", array(), 'goodsid');
			$goods = pdo_fetchall("SELECT g.id, g.title, g.thumb, g.unit, g.marketprice, o.total,o.optionid FROM " . tablename('shopping_order_goods')
					. " o left join " . tablename('shopping_goods') . " g on o.goodsid=g.id " . " WHERE o.orderid='{$orderid}'");
			foreach ($goods as &$g) {
				//属性
				$option = pdo_fetch("select title,marketprice,weight,stock from " . tablename("shopping_goods_option") . " where id=:id limit 1", array(":id" => $g['optionid']));
				if ($option) {
					$g['title'] = "[" . $option['title'] . "]" . $g['title'];
					$g['marketprice'] = $option['marketprice'];
				}
			}
			unset($g);
			$dispatch = pdo_fetch("SELECT id,dispatchname,enabled FROM " . tablename('shopping_dispatch') . ' WHERE id=:id ', array(":id" => $item['dispatch']));
			include $this->template('order_detail');
		} else if($op == 'important'){
			//专家提示为重要订单 cqn 8/19

			    pdo_update("shopping_order", array('important'=>1), array("id" => $_GPC['id']));
			    $expert = pdo_fetch("select * from ".tablename("shopping_order")." where id = '".$_GPC['id']."'");
	            $expertopenid = $expert['zjopenid'];
	            $expertinfo = pdo_fetch("select * from ".tablename("shopping_goods")." where openid = '".$expertopenid."'");
	            $expertphone = $expertinfo['phone'];
	            //重要给客服发短信
	            $uniontid = substr($expert['uniontid'],8,15);
			    sendtext($expertphone,9,$expertinfo['title'],$uniontid);
	            //重要给客服发模板消息
	            $sendinfo= pdo_fetch("select * from".tablename('shopping_sendwechatsetting'));
	            $openid = $sendinfo['seropenid'];
	            $data= $sendinfo['remark5'];
	            $this->send_templete_message($openid,9,$data,$_W['siteroot'],$_GPC['id']);
			    die(json_encode(array("status" => 1)));
		
		}
		 else {
			$pindex = max(1, intval($_GPC['page']));
			$psize = 5;
			$status = intval($_GPC['status']);
			if($_GPC['mark']==0)
			{
				$where = "from_user = '{$user['openid']}' ";
				if (!empty($status)) {
					if($status==2)
					{
						$where.=" and status>=2 ";
					}
					else
					{
						$where.=" and status=$status ";
					}
				
				}
				else{
					$where .= " and status=0 ";
				} 
			}
			//专家鉴宝管理 2016/08/10 cqn
			if ($_GPC['mark']==1) {
				$expertinfo = pdo_fetch("select id from " .tablename('shopping_goods'). " where openid='".$_W['openid']."'");
				$expertid = $expertinfo['id'];
				$where =" zjopenid='".$_W['openid']."' ";
				if (!empty($status)) {
					if($status=='2')
					{
						$where.=" and status!=0 and status!=1 and reson!=1";
					}
					else
					{
						$where.=" and status=1  or (reson=1 and zjopenid='".$_W['openid']."') ";
					}
					
				} 
				
			}

			
			
			if($status == 1)
			{
				$order = 'paishjian ASC';
			}

			else
			{
				$order = 'id DESC';
			}
			

			//var_dump($where);
			$list = pdo_fetchall("SELECT * FROM " . tablename('shopping_order') . " WHERE $where ORDER BY $order  LIMIT " . ($pindex - 1) * $psize . ',' . $psize, array(), 'id');
			//var_dump($list);
			//var_dump($where);
			$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_order') . " WHERE $where");
			$pager = pagination($total, $pindex, $psize);
			if (!empty($list)) {
				foreach ($list as &$row) {
					//var_dump($row['upimg']);
					$upimg =unserialize($row['upimg']);
					//var_dump($upimg[0]);
					$goodsid = pdo_fetchall("SELECT goodsid,total FROM " . tablename('shopping_order_goods') . " WHERE orderid = '{$row['id']}'", array(), 'goodsid');
					$goods = pdo_fetchall("SELECT g.id, g.title, g.thumb, g.unit, g.marketprice,o.total,o.optionid FROM " . tablename('shopping_order_goods') . " o left join " . tablename('shopping_goods') . " g on o.goodsid=g.id "
							. " WHERE o.orderid='{$row['id']}'");
					//var_dump($goods);
					foreach ($goods as &$item) {
						//属性
						$option = pdo_fetch("select title,marketprice,weight,stock from " . tablename("shopping_goods_option") . " where id=:id limit 1", array(":id" => $item['optionid']));
						if ($option) {
							$item['title'] = "[" . $option['title'] . "]" . $item['title'];
							$item['marketprice'] = $option['marketprice'];
							$item['mark'] = $user['mark'];
						}
						

					}
					$row['url']  = $this->createMobileUrl('case',array('id'=>$row['id'],'jieshu'=>1,'yjd'=>1));
					//var_dump($item);
					$row['contexts'] = mb_substr($row['context'],0,50,'utf-8');
            		 if((strlen($val['context'])/3) > 50){
                		$goods[$key]['context'] .= "...";
            		}
					$row['goods'] = $goods;
					$row['upimg'] = $upimg[0];
 					$row['total'] = $goodsid;
 					$row['kfphone'] = $kfphone;
 					if($row['zspay']>=1)
					{
							$certinfo = pdo_fetch("select wuliu from " .tablename('shopping_certificate'). " where orderid='".$row['id']."'");
							$row['wuliu'] = $certinfo['wuliu'];
					}
 					//var_dump($row['id']);
					//订单列表页宝贝链接
 					//专家个人中心
 					if($_GPC['mark']==1)
 					{
 						//var_dump($row['status']);
 						//var_dump($row['zjyjd']);
 						if($row['status']==-1)
 						{
 							if($row['zjyjd']==0)
 							{
 								$row['wd'] = 0;
 							}
 								
 						}
 						else if($row['status']==1)
 						{
 							//专家已超时，不能鉴定订单
 							if(TIMESTAMP > $row['paishjian'])
 							{
 								$row['url']="yichaoshi";	
 							}
 							else
 							{
 								$row['url'] = $this->createMobileUrl('zjhuifu',array('orderid'=>$row['id'],'yidu2'=>1));
 							}
 							if($row['yidu2']==0)
 							{
 								$row['wd']= 0;
 							}
 						}
 						else
 						{
 							if($row['zjyjd']==0)
 							{
 								$row['wd'] = 0;
 							}
 						}
 					}
 					//会员个人中心
 					else
 					{
 						if($row['status']>=2)
 						{
                            if($row['wuliu']){
                                $row['url'] = $this->createMobileUrl('case',array('id'=>$row['id'],'jieshu'=>1,'zhengshu'=>1));
                            }else{
                                $row['url'] = $this->createMobileUrl('case',array('id'=>$row['id'],'jieshu'=>1));
                            }
                            if($row['yjd']==0)
                            {
                            	$row['wd'] = 0;
                            }
 						   
 						}
 						else
 						{
 						   $row['url'] = $this->createMobileUrl('case_detail',array('id'=>$row['id'],'status'=>$row['status'],'yidu'=>1));
 						   if($row['status']==1 && $row['yidu']==0)
 						   {
                            	$row['wd'] = 0;
 						   }
 						   if($row['status']==1 && $row['yidu']==0)
 						   {
 						   		$row['wd'] = 0;
 						   }

 						}
 					}
					$row['dispatch'] = pdo_fetch("select id,dispatchname from " . tablename('shopping_dispatch') . " where id=:id limit 1", array(":id" => $row['dispatch']));
					$row['djstime']=date('Y/m/d H:i:s', $row['paishjian']);
					$row['mark']= $_GPC['mark'];
					$row['sqzslink'] = $this->createMobileUrl('zsagreement', array('orderid' => $row['id']));
					if(TIMESTAMP > $row['paishjian'])
					{
						$row['djstime1'] = 1;
					}

				}
			}
			//var_dump($list);
			if($_POST)
			{
				//取消鉴宝待支付订单
				if($_GPC['act']=="cancelorder")
				{
					$id = $_GPC['orderid'];
					pdo_delete('shopping_order', array('id' => $id));
					die(json_encode(array("status" => 1)));
				}
				//取消证书待支付订单
				if($_GPC['act']=="cancelcert")
				{
					$id = $_GPC['orderid'];
					pdo_delete('shopping_certificate', array('orderid' => $id));
					die(json_encode(array("status" => 1)));
				}
				//证书待支付
				elseif ($_GPC['act'] == 'weixinpay')
				{
					$order = pdo_fetch("select orderid from " .tablename('shopping_certificate')." where orderid='".$_GPC['orderid']."'");
					$orderinfo = pdo_fetch("select zjopenid,status from " .tablename('shopping_order')." where id='".$_GPC['orderid']."' ");
					if(!empty($order['orderid']))
					{
							
						$data = array();
						$wOpt = $this->getowpt($_GPC['price'],'申请证书');
						$data['status'] = 1;
						$data['role'] = 'fans';
						$data['appId'] = $wOpt['appId'];
						$data['uniontid'] = $wOpt['uniontid'];
						$data['timeStamp'] = $wOpt['timeStamp'];
						$data['nonceStr'] = $wOpt['nonceStr'];
						$data['package'] = $wOpt['package'];
						$data['signType'] = $wOpt['signType'];
						$data['paySign'] = $wOpt['paySign'];
						$data['ordersn'] = $ordersn;
						$data['orderid'] = $_GPC['orderid'];
						pdo_update("shopping_certificate", array('uniontid'=>$wOpt['uniontid']), array("orderid" => $_GPC['orderid']));
						die(json_encode($data));
					}
					if($orderinfo['status']==1 || $orderinfo['status']==2 || $orderinfo['status']==-1)
					{
						die(json_encode(array("status" => 0)));
					}
					if($act == 'post_success'){
						$orderid = $_GPC['orderid'];
						$datastatus['status'] = 1; 
						$datastatus['paytime'] = time();
						pdo_update("shopping_certificate", $datastatus, array("orderid" => $orderid));
						pdo_update("shopping_order",array('zspay'=>1),array('id'=>$orderid));
			                //申请证书给专家发短信
			            $expert = pdo_fetch("select * from ".tablename("shopping_order")." where id = '".$orderid."'");
			            $expertopenid = $expert['zjopenid'];
			            $expertinfo = pdo_fetch("select phone from ".tablename("shopping_goods")." where openid = '".$expertopenid."'");
			            $expertphone = $expertinfo['phone'];
			            


			            sendtext($expertphone,6,0,substr($expert['uniontid'],8,15));
			            //申请证书给客服发模板消息
			            $sendinfo= pdo_fetch("select * from".tablename('shopping_sendwechatsetting'));
			            $openid = $sendinfo['seropenid'];
			            $data= $sendinfo['remark5'];
			            send_templete_messages($openid,6,$data,$_W['siteroot'],$orderid);
			            //申请证书给专家发模板消息
			            send_templete_messages($expertopenid,6,$data,$_W['siteroot']."app/".$this->createMobileUrl('zjcertificate',array('openid' => $expertopenid)),$orderid);
						$datares = array();
						$datares['ispay'] = 1;
						die(json_encode($datares));
				}

				}
				//证书待支付慢加载
				elseif($_GPC['zsmjz'])
				{
					$order = pdo_fetchall("select * from " .tablename('shopping_certificate')." where  status=0 and openid='".$_W['openid']."'");
					foreach ($order as $key => $val) 
					{
						$order[$key]['certlist'] = pdo_fetch("select * from " .tablename('shopping_order')." where id=".$val['orderid']);
						$upimg =unserialize($order[$key]['certlist']['upimg']);
						$order[$key]['certlist']['upimg'] = $upimg[0];
					}
				}
				else
				{
					return json_encode($list);
					exit;
				}
				
			}
			//待支付的订单
			if($_GPC['status']==0 && $_GPC['op']=="daizhifu")
			{
				$list = pdo_fetchall("select * from ".tablename('shopping_order')." where status=0 and from_user='".$_W['openid']."' order by id desc");
				foreach ($list as $key => $val) {
					$upimg =unserialize($val['upimg']);
					$list[$key]['upimgs']= $upimg[0];
				}
				$order = pdo_fetchall("select * from " .tablename('shopping_certificate')." where  status=0 and openid='".$_W['openid']."' order by id desc");
				foreach ($order as $key => $val) {
					$order[$key]['certlist'] = pdo_fetch("select * from " .tablename('shopping_order')." where id=".$val['orderid']);
					$upimg =unserialize($order[$key]['certlist']['upimg']);
					$order[$key]['certlist']['upimg'] = $upimg[0];
				}
				//var_dump($order);

				$title = "鉴宝";
				include $this->template('daizhifu');
			}
			else
			{
				$title = "我的鉴定";
				include $this->template('order');
			}
			
			
		}
        }else{
            include $this->template('register');
        }
	}
	public function doMobileDetail() {
		global $_W, $_GPC;
		$goodsid = intval($_GPC['id']);
		$goods = pdo_fetch("SELECT * FROM " . tablename('shopping_goods') . " WHERE id = :id ", array(':id' => $goodsid));
		if (empty($goods)) {
			message('抱歉，专家不存在或是已经被删除！');
		}
		if ($goods['istime'] == 1) {
			$backUrl = $this->createMobileUrl('list');
			$backUrl = $_W['siteroot'] . 'app' . ltrim($backUrl, '.');
			if (time() < $goods['timestart']) {
				message('抱歉，还未到购买时间, 暂时无法购物哦~', $backUrl, "error");
			}
			if (time() > $goods['timeend']) {
				message('抱歉，专家限购时间已到，不能购买了哦~', $backUrl, "error");
			}
		}
		$title = $goods['title'];
		//浏览量
		pdo_query("update " . tablename('shopping_goods') . " set viewcount=viewcount+1 where id=:id ", array(":id" => $goodsid));
		$piclist1 = array(array("attachment" => $goods['thumb']));
		$piclist = array();
		if (is_array($piclist1)) {
			foreach($piclist1 as $p){
				$piclist[] = is_array($p)?$p['attachment']:$p;
			}
		}
		if ($goods['thumb_url'] != 'N;') {
			$urls = unserialize($goods['thumb_url']);
			if (is_array($urls)) {
				foreach($urls as $p){
					$piclist[] = is_array($p)?$p['attachment']:$p;
				}
			}
		}
		$marketprice = $goods['marketprice'];
		$productprice= $goods['productprice'];
		$originalprice = $goods['originalprice'];
		$stock = $goods['total'];
		//规格及规格项
		$allspecs = pdo_fetchall("select * from " . tablename('shopping_spec') . " where goodsid=:id order by displayorder asc", array(':id' => $goodsid));
		foreach ($allspecs as &$s) {
			$s['items'] = pdo_fetchall("select * from " . tablename('shopping_spec_item') . " where  `show`=1 and specid=:specid order by displayorder asc", array(":specid" => $s['id']));
		}
		unset($s);
		//处理规格项
		$options = pdo_fetchall("select id,title,thumb,marketprice,productprice,costprice, stock,weight,specs from " . tablename('shopping_goods_option') . " where goodsid=:id order by id asc", array(':id' => $goodsid));
		//排序好的specs
		$specs = array();
		//找出数据库存储的排列顺序
		if (count($options) > 0) {
			$specitemids = explode("_", $options[0]['specs'] );
			foreach($specitemids as $itemid){
				foreach($allspecs as $ss){
					$items = $ss['items'];
					foreach($items as $it){
						if($it['id']==$itemid){
							$specs[] = $ss;
							break;
						}
					}
				}
			}
		}
		$params = pdo_fetchall("SELECT * FROM " . tablename('shopping_goods_param') . " WHERE goodsid=:goodsid order by displayorder asc", array(":goodsid" => $goods['id']));
		$carttotal = $this->getCartTotal();
		include $this->template('detail');
	}

	public function doMobileAddress() {
		global $_W, $_GPC;
		$this->checkAuth();
		$operation = $_GPC['op'];

		if ($operation == 'post') {
			$id = intval($_GPC['id']);
			$data = array(
				'uniacid' => $_W['uniacid'],
				'uid' => $_W['fans']['uid'],
				'username' => $_GPC['realname'],
				'mobile' => $_GPC['mobile'],
				'province' => $_GPC['province'],
				'city' => $_GPC['city'],
				'district' => $_GPC['area'],
				'address' => $_GPC['address'],
			);
			if (empty($data['username']) || empty($data['mobile']) || empty($data['address'])) {
				message('请输完善您的资料！');
			}
			if (!empty($id)) {
				unset($data['uniacid']);
				unset($data['uid']);
				pdo_update('mc_member_address', $data, array('id' => $id));
				message($id, '', 'ajax');
			} else {
				pdo_update('mc_member_address', array('isdefault' => 0), array('uniacid' => $_W['uniacid'], 'uid' => $_W['fans']['uid']));
				$data['isdefault'] = 1;
				pdo_insert('mc_member_address', $data);
				pdo_update('mc_members', array('address' => $data['province'].$data['city'].$data['district'].$data['address']), array('uniacid' => $_W['uniacid'], 'uid' => $_W['fans']['uid']));
				$id = pdo_insertid();
				if (!empty($id)) {
					message($id, '', 'ajax');
				} else {
					message(0, '', 'ajax');
				}
			}
		} elseif ($operation == 'default') {
			$id = intval($_GPC['id']);
			$sql = 'SELECT * FROM ' . tablename('mc_member_address') . ' WHERE `id` = :id AND `uniacid` = :uniacid
					 AND `uid` = :uid';
			$params = array(':id' => $id, ':uniacid' => $_W['uniacid'], ':uid' => $_W['fans']['uid']);
			$address = pdo_fetch($sql, $params);

			if (!empty($address) && empty($address['isdefault'])) {
				pdo_update('mc_member_address', array('isdefault' => 0), array('uniacid' => $_W['uniacid'], 'uid' => $_W['fans']['uid']));
				pdo_update('mc_member_address', array('isdefault' => 1), array('uniacid' => $_W['uniacid'], 'uid' => $_W['fans']['uid'], 'id' => $id));
				pdo_update('mc_members', array('address' => $address['province'].$address['city'].$address['district'].$address['address']), array('uniacid' => $_W['uniacid'], 'uid' => $_W['fans']['uid']));
			}
			message(1, '', 'ajax');
		} elseif ($operation == 'detail') {
			$id = intval($_GPC['id']);
			$sql = 'SELECT * FROM ' . tablename('mc_member_address') . ' WHERE `id` = :id';
			$row = pdo_fetch($sql, array(':id' => $id));
			message($row, '', 'ajax');
		} elseif ($operation == 'remove') {
			$id = intval($_GPC['id']);
			if (!empty($id)) {
				$where = ' AND `uniacid` = :uniacid AND `uid` = :uid';
				$sql = 'SELECT `isdefault` FROM ' . tablename('mc_member_address') . ' WHERE `id` = :id' . $where;
				$params = array(':id' => $id, ':uniacid' => $_W['uniacid'], ':uid' => $_W['fans']['uid']);
				$address = pdo_fetch($sql, $params);

				if (!empty($address)) {
					pdo_delete('mc_member_address', array('id' => $id));
					// 如果删除的是默认地址，则设置是新的为默认地址
					if ($address['isdefault'] > 0) {
						$sql = 'SELECT MAX(id) FROM ' . tablename('mc_member_address') . ' WHERE 1 ' . $where;
						unset($params[':id']);
						$maxId = pdo_fetchcolumn($sql, $params);
						if (!empty($maxId)) {
							pdo_update('mc_member_address', array('isdefault' => 1), array('id' => $maxId));
							die(json_encode(array("result" => 1, "maxid" => $maxId)));
						}
					}
				}
			}
			die(json_encode(array("result" => 1, "maxid" => 0)));
		} else {
			$sql = 'SELECT * FROM ' . tablename('mc_member_address') . ' WHERE `uniacid` = :uniacid AND `uid` = :uid';
			$params = array(':uniacid' => $_W['uniacid']);
			if (empty($_W['member']['uid'])) {
				$params[':uid'] = $_W['fans']['openid'];
			} else {
				$params[':uid'] = $_W['member']['uid'];
			}
			$addresses = pdo_fetchall($sql, $params);
			$carttotal = $this->getCartTotal();
			include $this->template('address');
		}
	}

	private function checkAuth() {
		global $_W;
		$setting = cache_load('unisetting:'.$_W['uniacid']);
		if (empty($_W['member']['uid']) && empty($setting['passport']['focusreg'])) {
			$fan = pdo_get('mc_mapping_fans', array('uniacid' =>$_W['uniacid'], 'openid' => $_W['openid']));
			if (!empty($fan)) {
				$fanid = $fan['fanid'];
			} else {
				$post = array(
					'uniacid' => $_W['uniacid'],
					'updatetime' => time(),
					'openid' => $_W['openid'],
					'follow' => 0,
				);
				pdo_insert('mc_mapping_fans', $post);
				$fanid =  pdo_insertid();
			}
			if (empty($fan['uid'])) {
				pdo_insert('mc_members', array('uniacid' => $_W['uniacid']));
				$uid = pdo_insertid();
				$_W['member']['uid'] = $uid;
				$_W['fans']['uid'] = $uid;
				pdo_update('mc_mapping_fans', array('uid' => $uid), array('fanid' => $fanid));
			} else {
				$_W['member']['uid'] = $fan['uid'];
				$_W['fans']['uid'] = $fan['uid'];
			}
		} else {
			checkauth();
		}
	}
	private function changeWechatSend($id, $status, $msg = '') {
		global $_W;
		$paylog = pdo_fetch("SELECT plid, openid, tag FROM " . tablename('core_paylog') . " WHERE tid = '{$id}' AND status = 1 AND type = 'wechat'");
		if (!empty($paylog['openid'])) {
			$paylog['tag'] = iunserializer($paylog['tag']);
			$acid = $paylog['tag']['acid'];
			$account = account_fetch($acid);
			$payment = uni_setting($account['uniacid'], 'payment');
			if ($payment['payment']['wechat']['version'] == '2') {
				return true;
			}
			$send = array(
					'appid' => $account['key'],
					'openid' => $paylog['openid'],
					'transid' => $paylog['tag']['transaction_id'],
					'out_trade_no' => $paylog['plid'],
					'deliver_timestamp' => TIMESTAMP,
					'deliver_status' => $status,
					'deliver_msg' => $msg,
			);
			$sign = $send;
			$sign['appkey'] = $payment['payment']['wechat']['signkey'];
			ksort($sign);
			$string = '';
			foreach ($sign as $key => $v) {
				$key = strtolower($key);
				$string .= "{$key}={$v}&";
			}
			$send['app_signature'] = sha1(rtrim($string, '&'));
			$send['sign_method'] = 'sha1';
			$account = WeAccount::create($acid);
			$response = $account->changeOrderStatus($send);
			if (is_error($response)) {
				message($response['message']);
			}
		}
	}
	public function payResult($params) {
		global $_W;
		$fee = intval($params['fee']);
		$data = array('status' => $params['result'] == 'success' ? 1 : 0);
		$paytype = array('credit' => '1', 'wechat' => '2', 'alipay' => '2', 'delivery' => '3');

		// 卡券代金券备注
		if (!empty($params['is_usecard'])) {
			$cardType = array('1' => '微信卡券', '2' => '系统代金券');
			$data['paydetail'] = '使用' . $cardType[$params['card_type']] . '支付了' . ($params['fee'] - $params['card_fee']);
			$data['paydetail'] .= '元，实际支付了' . $params['card_fee'] . '元。';
		}
		$data['paytype'] = $paytype[$params['type']];
		if ($paytype[$params['type']] == '') {
			$data['paytype'] = 4;
		}
		if ($params['type'] == 'wechat') {
			$data['transid'] = $params['tag']['transaction_id'];
		}
		if ($params['type'] == 'delivery') {
			$data['status'] = 1;
		}

		if ($_SESSION['ewei_shopping_pay_result'] != $params['tid']) {
			session_start();
			$_SESSION['ewei_shopping_pay_result'] = $params['tid'];
			$pay_status = pdo_get('shopping_order', array('id' =>$params['tid']));
			$pay_status = $pay_status['status'];
			$goods = pdo_fetchall("SELECT `goodsid`, `total`, `optionid` FROM " . tablename('shopping_order_goods') . " WHERE `orderid` = :orderid", array(':orderid' => $params['tid']));
			if (!empty($goods)) {
				$row = array();
				foreach ($goods as $row) {
					$goodsInfo = pdo_fetch("SELECT `total`, `totalcnf`, `sales` FROM " . tablename('shopping_goods') . " WHERE `id` = :id", array(':id' => $row['goodsid']));
					$goodsupdate = array();
					if ($goodsInfo['totalcnf'] == '1' && !empty($goodsInfo['total'])) {
						$goodsupdate['total'] = $goodsInfo['total'] - $row['total'];
						$goodsupdate['total'] = ($goodsupdate['total'] < 0) ? 0 : $goodsupdate['total'];
					}
					$goodsupdate['sales'] = $goodsInfo['sales'] + $row['total'];
					if ($pay_status != 1) {
						pdo_update('shopping_goods', $goodsupdate, array('id' => $row['goodsid']));
					}
					$optionInfo = pdo_fetch("SELECT `stock` FROM " . tablename('shopping_goods_option') . " WHERE `id` = :id", array(':id' => $row['optionid']));
					$options = array();
					if ($goodsInfo['totalcnf'] == '1' && !empty($optionInfo['stock'])) {
						$options['stock'] = $optionInfo['stock'] - $row['total'];
						$options['stock'] = ($optionInfo['stock'] < 0) ? 0 : $options['stock'];
						if ($pay_status != 1) {
							pdo_update('shopping_goods_option', $options, array('id' => $row['optionid']));
						}
					}
				}
			}
			pdo_update('shopping_order', $data, array('id' => $params['tid']));
		}else {
			$setting = uni_setting($_W['uniacid'], array('creditbehaviors'));
			$credit = $setting['creditbehaviors']['currency'];
			if ($params['type'] == $credit) {
				message('支付成功！', $this->createMobileUrl('myorder', array('status' => 2)), 'success');
			} else {
				message('支付成功！', '../../app/' . $this->createMobileUrl('myorder', array('status' => 2)), 'success');
			}
		}
		if ($params['from'] == 'return') {
			//积分变更
			$this->setOrderCredit($params['tid']);

			if (!empty($this->module['config']['noticeemail']) || !empty($this->module['config']['template'])|| !empty($this->module['config']['mobile'])) {
				$order = pdo_fetch("SELECT `ordersn`, `price`, `paytype`, `from_user`, `address`, `createtime` FROM " . tablename('shopping_order') . " WHERE id = '{$params['tid']}'");
				$ordergoods = pdo_fetchall("SELECT goodsid, total FROM " . tablename('shopping_order_goods') . " WHERE orderid = '{$params['tid']}'", array(), 'goodsid');
				$goods = pdo_fetchall("SELECT id, title, thumb, marketprice, unit, total FROM " . tablename('shopping_goods') . " WHERE id IN ('" . implode("','", array_keys($ordergoods)) . "')");
//				$address = pdo_fetch("SELECT * FROM " . tablename('mc_member_address') . " WHERE id = :id", array(':id' => $order['addressid']));
				$address = explode('|', $order['address']);

				// 邮件提醒
				if (!empty($this->module['config']['noticeemail'])) {
					$body = "<h3>购买专家清单</h3> <br />";
					if (!empty($goods)) {
						foreach ($goods as $row) {
							$body .= "名称：{$row['title']} ，数量：{$ordergoods[$row['id']]['total']} <br />";
						}
					}
					$paytype = $order['paytype'] == '3' ? '货到付款' : '已付款' . '<br />';
					$body .= '总金额：' . $order['price'] . '元' . $paytype . '<br />';
					$body .= '<h3>购买用户详情</h3> <br />';
					$body .= '真实姓名：' . $address[0] . '<br />';
					$body .= '地区：' . $address[3] . ' - ' . $address[4] . ' - ' . $address[5] . '<br />';
					$body .= '详细地址：' . $address[6] . '<br />';
					$body .= '手机：' . $address[1]  . '<br />';

					load()->func('communication');
					ihttp_email($this->module['config']['noticeemail'], '微商城订单提醒', $body);
				}
				//模板消息
				if (!empty($this->module['config']['template'])) {
					$good = '';
					$address = explode('|', $order['address']);
					if (!empty($goods)) {
						foreach ($goods as $row) {
							$good .= "\n"."名称：{$row['title']} ，数量：{$ordergoods[$row['id']]['total']} ";
						}
					}
					$paytype = $order['paytype'] == '3' ? '货到付款' : '已付款';
					$data = array (
						'first' => array('value' => '购买专家清单'),
						'keyword1' => array('value' => date('Y-m-d H:i',strtotime('now'))),
						'keyword2' => array('value' => "\n".$good),
						'keyword3' => array('value' => $order['price']),
						'keyword4' => array('value' => "\n".'真实姓名：' . $address[0]."\n".'地区：' . $address[3] . ' - ' . $address[4] . ' - ' . $address[5]."\n".'详细地址：' . $address[6] ."\n".'手机：' . $address[1]),
						'keyword5' => array('value' => $paytype)
					);
					$acc = WeAccount::create($_W['acid']);
					$acc->sendTplNotice($_W['fans']['from_user'],$this->module['config']['templateid'],$data);
				}
				// 短信提醒
				if (!empty($this->module['config']['mobile'])) {
					load()->model('cloud');
					cloud_prepare();

					$body = '用户' . $address[0] . ',电话:' . $address[1] . '于' . date('m月d日H:i') . '成功支付订单' . $order['ordersn']
						. ',总金额' . $order['price'] . '元' . '.' . random(3);

					cloud_sms_send($this->module['config']['mobile'], $body);
				}
			}

			$setting = uni_setting($_W['uniacid'], array('creditbehaviors'));
			$credit = $setting['creditbehaviors']['currency'];
			if ($params['type'] == $credit) {
				message('支付成功！', $this->createMobileUrl('myorder'), 'success');
			} else {
				message('支付成功！', '../../app/' . $this->createMobileUrl('myorder'), 'success');
			}
		}
	}
	public function doWebOption() {
		$tag = random(32);
		global $_GPC;
		include $this->template('option');
	}
	public function doWebSpec() {
		global $_GPC;
		$spec = array(
			"id" => random(32),
			"title" => $_GPC['title']
		);
		include $this->template('spec');
	}
	public function doWebSpecItem() {
		global $_GPC;
		load()->func('tpl');
		$spec = array(
			"id" => $_GPC['specid']
		);
		$specitem = array(
			"id" => random(32),
			"title" => $_GPC['title'],
			"show" => 1
		);
		include $this->template('spec_item');
	}
	public function doWebParam() {
		$tag = random(32);
		global $_GPC;
		include $this->template('param');
	}
	public function doWebExpress() {
		global $_W, $_GPC;
		// pdo_query('DROP TABLE ims_shopping_express');
		//pdo_query("CREATE TABLE IF NOT EXISTS `ims_shopping_express` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `weid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '所属帐号',  `express_name` varchar(50) NOT NULL COMMENT '分类名称',  `express_price` varchar(10) NOT NULL DEFAULT '0',  `displayorder` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '排序',  `express_area` varchar(50) NOT NULL COMMENT '配送区域',  `enabled` tinyint(1) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 ");
		//pdo_query("ALTER TABLE  `ims_shopping_order` ADD  `expressprice` VARCHAR( 10 ) NOT NULL AFTER  `totalnum` ;");
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('shopping_express') . " ORDER BY displayorder DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				if (empty($_GPC['express_name'])) {
					message('抱歉，请输入物流名称！');
				}
				$data = array(
					'displayorder' => intval($_GPC['displayorder']),
					'express_name' => $_GPC['express_name'],
					'express_url' => $_GPC['express_url'],
					'express_area' => $_GPC['express_area'],
				);
				if (!empty($id)) {
					unset($data['parentid']);
					pdo_update('shopping_express', $data, array('id' => $id));
				} else {
					pdo_insert('shopping_express', $data);
					$id = pdo_insertid();
				}
				message('更新物流成功！', $this->createWebUrl('express', array('op' => 'display')), 'success');
			}
			//修改
			$express = pdo_fetch("SELECT * FROM " . tablename('shopping_express') . " WHERE id = '$id' ");
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$express = pdo_fetch("SELECT id  FROM " . tablename('shopping_express') . " WHERE id = '$id' ");
			if (empty($express)) {
				message('抱歉，物流方式不存在或是已经被删除！', $this->createWebUrl('express', array('op' => 'display')), 'error');
			}
			pdo_delete('shopping_express', array('id' => $id));
			message('物流方式删除成功！', $this->createWebUrl('express', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('express', TEMPLATE_INCLUDEPATH, true);
	}
	public function doWebDispatch() {
		global $_W, $_GPC;
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('shopping_dispatch') . "  ORDER BY displayorder DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'displayorder' => intval($_GPC['displayorder']),
					'dispatchtype' => intval($_GPC['dispatchtype']),
					'dispatchname' => $_GPC['dispatchname'],
					'express' => $_GPC['express'],
					'firstprice' => $_GPC['firstprice'],
					'firstweight' => $_GPC['firstweight'],
					'secondprice' => $_GPC['secondprice'],
					'secondweight' => $_GPC['secondweight'],
					'description' => $_GPC['description'],
                    'enabled'  => $_GPC['enabled']
				);
				if (!empty($id)) {
					pdo_update('shopping_dispatch', $data, array('id' => $id));
				} else {
					pdo_insert('shopping_dispatch', $data);
					$id = pdo_insertid();
				}
				message('更新配送方式成功！', $this->createWebUrl('dispatch', array('op' => 'display')), 'success');
			}
			//修改
			$dispatch = pdo_fetch("SELECT * FROM " . tablename('shopping_dispatch') . " WHERE id = '$id'");
			$express = pdo_fetchall("select * from " . tablename('shopping_express') . " ORDER BY displayorder DESC");
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$dispatch = pdo_fetch("SELECT id FROM " . tablename('shopping_dispatch') . " WHERE id = '$id' ");
			if (empty($dispatch)) {
				message('抱歉，配送方式不存在或是已经被删除！', $this->createWebUrl('dispatch', array('op' => 'display')), 'error');
			}
			pdo_delete('shopping_dispatch', array('id' => $id));
			message('配送方式删除成功！', $this->createWebUrl('dispatch', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('dispatch', TEMPLATE_INCLUDEPATH, true);
	}
	public function doWebAdv() {
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('shopping_adv') . "  ORDER BY displayorder ASC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'advname' => $_GPC['advname'],
					'link' => $_GPC['link'],
					'enabled' => intval($_GPC['enabled']),
					'displayorder' => intval($_GPC['displayorder']),
					'thumb'=>$_GPC['thumb']
				);
				if (!empty($id)) {
					pdo_update('shopping_adv', $data, array('id' => $id));
				} else {
					pdo_insert('shopping_adv', $data);
					$id = pdo_insertid();
				}
				message('更新幻灯片成功！', $this->createWebUrl('adv', array('op' => 'display')), 'success');
			}
			$adv = pdo_fetch("select * from " . tablename('shopping_adv') . " where id=:id  limit 1", array(":id" => $id));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$adv = pdo_fetch("SELECT id FROM " . tablename('shopping_adv') . " WHERE id = '$id' ");
			if (empty($adv)) {
				message('抱歉，幻灯片不存在或是已经被删除！', $this->createWebUrl('adv', array('op' => 'display')), 'error');
			}
			pdo_delete('shopping_adv', array('id' => $id));
			message('幻灯片删除成功！', $this->createWebUrl('adv', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('adv', TEMPLATE_INCLUDEPATH, true);
	}

	public function doWebmc(){
		global $_GPC, $_W;
		uni_user_permission_check('mc_member');
		if($_GET['act']=='post'){
			$do = 'post';
		}
		if($_GET['act']=='add'){
			$do = 'add';
		}
		if($_POST['act']=='del'){
			$do = 'del';
		}
		if($_GET['act']=='edit'){
			$do = 'edit';
		}
		if($_GET['act']=='display'){
			$do = 'display';
		}
		$dos = array('display', 'post','del', 'add', 'group', 'credit_record', 'credit_stat');
		$do = in_array($do, $dos) ? $do : 'display';
		load()->model('mc');
if($do == 'display') {
	$_W['page']['title'] = '会员列表 - 会员 - 会员中心';
	$groups = mc_groups();
	$pindex = max(1, intval($_GPC['page']));
	$psize = 50;
	$condition = '';
	$starttime = empty($_GPC['createtime']['start']) ? strtotime('-90 days') : strtotime($_GPC['createtime']['start']);
	$endtime = empty($_GPC['createtime']['end']) ? TIMESTAMP + 86399 : strtotime($_GPC['createtime']['end']) + 86399;
	$condition .= "createtime >= {$starttime} AND createtime <= {$endtime}";
	$condition .= empty($_GPC['username']) ? '' : " AND (( `realname` LIKE '%".trim($_GPC['username'])."%' ) OR ( `nickname` LIKE '%".trim($_GPC['username'])."%' ) OR ( `mobile` LIKE '%".trim($_GPC['username'])."%' )";
	if (!empty($_GPC['username'])) {
		if (!is_numeric(trim($_GPC['username']))) {
			$uid = pdo_fetchcolumn('SELECT `uid` FROM'. tablename('mc_mapping_fans')." WHERE openid = :openid", array(':openid' => trim($_GPC['username'])));
			$condition .= " OR ( `uid` = '$uid'))";
		} else {
			$condition .= ")";
		}
	}
	//var_dump($condition);
	$condition .= intval($_GPC['groupid']) > 0 ?  " AND `groupid` = '".intval($_GPC['groupid'])."'" : '';
	if(checksubmit('export_submit', true)) {
		$sql = "SELECT uid, uniacid, groupid, realname, nickname, email, mobile, credit1, credit2, credit6, createtime  FROM ".tablename('mc_members')." WHERE ".$condition." ORDER BY createtime";
		$list = pdo_fetchall($sql);
		$header = array(
			'uid' => 'UID', 'nickname' => '昵称',  'mobile' => '手机','createtime' => '注册时间',
		);
		$keys = array_keys($header);
		$html = "\xEF\xBB\xBF";
		foreach($header as $li) {
			$html .= $li . "\t ,";
		}
		$html .= "\n";
		if(!empty($list)) {
			$size = ceil(count($list) / 500);
			for($i = 0; $i < $size; $i++) {
				$buffer = array_slice($list, $i * 500, 500);
				foreach($buffer as $row) {
					if(strexists($row['email'], 'we7.cc')) {
						$row['email'] = '';
					}
					$row['createtime'] = date('Y-m-d H:i:s', $row['createtime']);
					$row['groupid'] = $groups[$row['groupid']]['title'];
					foreach($keys as $key) {
						$data[] = $row[$key];
					}
					$user[] = implode("\t ,", $data) . "\t ,";
					unset($data);
				}
			}
			$html .= implode("\n", $user);
		}
		
		header("Content-type:text/csv");
		header("Content-Disposition:attachment; filename=会员数据.csv");
		echo $html;
		exit();
	}
	$sql = "SELECT uid, uniacid, groupid, realname, nickname, email, mobile, credit1, credit2, credit6, createtime  FROM ".tablename('mc_members') ." WHERE  ".$condition." ORDER BY createtime DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize;
	$list = pdo_fetchall($sql);
	
	$total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('mc_members')." WHERE  ".$condition);
	$pager = pagination($total, $pindex, $psize);
	$stat['total'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_members'));
	$stat['today'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_members') . ' WHERE  createtime >= :starttime AND createtime <= :endtime', array(':starttime' => strtotime('today'), ':endtime' => strtotime('today') + 86399));
	$stat['yesterday'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_members') . ' WHERE createtime >= :starttime AND createtime <= :endtime', array(':starttime' => strtotime('today')-86399, ':endtime' => strtotime('today')));
}
elseif($do == 'post') {
	$_W['page']['title'] = '编辑会员资料 - 会员 - 会员中心';
	$uid = intval($_GPC['uid']);
	if ($_W['ispost'] && $_W['isajax']) {
		if ($_GPC['op'] == 'addaddress' || $_GPC['op'] == 'editaddress') {
			$post = array(
			'uniacid' => $_W['uniacid'],
			'province' => trim($_GPC['province']),
			'city' => trim($_GPC['city']),
			'district' => trim($_GPC['district']),
			'address' => trim($_GPC['detail']),
			'uid' => intval($_GPC['uid']),
			'username' => trim($_GPC['name']),
			'mobile' => trim($_GPC['phone']),
			'zipcode' => trim($_GPC['code'])
			);
			if ($_GPC['op'] == 'addaddress') {
				$sql = "SELECT COUNT(*) FROM ". tablename('mc_member_address'). " WHERE uid = :uid";
				$exist_address = pdo_fetchcolumn($sql, array(':uid' => $uid));
				if (!$exist_address) {
					$post['isdefault'] = 1;
				}
				pdo_insert('mc_member_address', $post);
				$post['id'] = pdo_insertid();
				message(error(1, $post), '', 'ajax');
			} else {
				pdo_update('mc_member_address', $post, array('id' => intval($_GPC['id'])));
				$post['id'] = intval($_GPC['id']);
				message(error(1, $post), '', 'ajax');
			}
		}
		if ($_GPC['op'] == 'del') {
			$id = intval($_GPC['id']);
			pdo_delete('mc_member_address', array('id' => $id));
			message(error(1), '', 'ajax');
		}
		if ($_GPC['op'] == 'isdefault') {
			$id = intval($_GPC['id']);
			$uid = intval($_GPC['uid']);
			pdo_update('mc_member_address', array('isdefault' => 0), array('uid' => $uid));
			pdo_update('mc_member_address', array('isdefault' => 1), array('id' => $id));
			message(error(1), '', 'ajax');
		}
		$password = $_GPC['password'];
		$sql = 'SELECT `uid`, `salt` FROM ' . tablename('mc_members') . " WHERE `uid` = :uid";
		$user = pdo_fetch($sql, array(':uid' => $uid));
		if(empty($user) || $user['uid'] != $uid) {
			exit('error');
		}
		$password = md5($password . $user['salt'] . $_W['config']['setting']['authkey']);
		if (pdo_update('mc_members', array('password' => $password), array('uid' => $uid))) {
			exit('success');
		}
		exit('othererror');
	}
	if (checksubmit('submit')) {
		$uid = intval($_GPC['uid']);
		if (!empty($_GPC)) {
			if (!empty($_GPC['birth'])) {
				$_GPC['birthyear'] = $_GPC['birth']['year'];
				$_GPC['birthmonth'] = $_GPC['birth']['month'];
				$_GPC['birthday'] = $_GPC['birth']['day'];
			}
			if (!empty($_GPC['reside'])) {
				$_GPC['resideprovince'] = $_GPC['reside']['province'];
				$_GPC['residecity'] = $_GPC['reside']['city'];
				$_GPC['residedist'] = $_GPC['reside']['district'];
			}
			unset($_GPC['uid']);
			if(!empty($_GPC['fanid'])) {
								if(empty($_GPC['email']) && empty($_GPC['mobile'])) {
					$_GPC['email'] = md5($_GPC['openid']) . '@we7.cc';
				}
				$fanid = intval($_GPC['fanid']);
								$struct = array_keys(mc_fields());
				$struct[] = 'birthyear';
				$struct[] = 'birthmonth';
				$struct[] = 'birthday';
				$struct[] = 'resideprovince';
				$struct[] = 'residecity';
				$struct[] = 'residedist';
				$struct[] = 'groupid';
				unset($_GPC['reside'], $_GPC['birth']);

				foreach ($_GPC as $field => $value) {
					if(!in_array($field, $struct)) {
						unset($_GPC[$field]);
					}
				}

				if(!empty($_GPC['avatar'])) {
					if(strexists($_GPC['avatar'], 'attachment/images/global/avatars/avatar_')) {
						$_GPC['avatar'] = str_replace($_W['attachurl'], '', $_GPC['avatar']);
					}
				}
				$condition = '';
								if(!empty($_GPC['email'])) {
					$emailexists = pdo_fetchcolumn("SELECT email FROM ".tablename('mc_members')." WHERE email = :email " . $condition, array(':email' => trim($_GPC['email'])));
					if($emailexists) {
						unset($_GPC['email']);
					}
				}
				if(!empty($_GPC['mobile'])) {
					$mobilexists = pdo_fetchcolumn("SELECT mobile FROM ".tablename('mc_members')." WHERE mobile = :mobile " . $condition, array(':mobile' => trim($_GPC['mobile'])));
					if($mobilexists) {
						unset($_GPC['mobile']);
					}
				}
				$_GPC['uniacid'] = $_W['uniacid'];
				$_GPC['createtime'] = TIMESTAMP;
				pdo_insert('mc_members', $_GPC);
				$uid = pdo_insertid();
				pdo_update('mc_mapping_fans', array('uid' => $uid), array('fanid' => $fanid));
				message('更新资料成功！', url('mc/member/post', array('uid' => $uid)), 'success');
			} else {
				$email_effective = intval($_GPC['email_effective']);
				if(($email_effective == 1 && empty($_GPC['email']))) {
					unset($_GPC['email']);
				}
				unset($_GPC['addresss']);
				$uid = mc_update($uid, $_GPC);
			}
		}
		message('更新资料成功！', referer(), 'success');
	}
	$groups = mc_groups($_W['uniacid']);
	$profile = pdo_get('mc_members', array('uid' => $uid));
	if(!empty($profile)) {
		if(empty($profile['email']) || (!empty($profile['email']) && substr($profile['email'], -6) == 'we7.cc' && strlen($profile['email']) == 39)) {
						$profile['email_effective'] = 1;
			$profile['email'] = '';
		} else {
						$profile['email_effective'] = 2;
		}
	}

	if(empty($uid)) {
		$fanid = intval($_GPC['fanid']);
		$tag = pdo_fetchcolumn('SELECT tag FROM ' . tablename('mc_mapping_fans') . ' WHERE fanid = :fanid', array(':fanid' => $fanid));
		if(is_base64($tag)){
			$tag = base64_decode($tag);
		}
		if(is_serialized($tag)){
			$fan = iunserializer($tag);
		}
		if(!empty($tag)) {
			if(!empty($fan['nickname'])) {
				$profile['nickname'] = $fan['nickname'];
			}
			if(!empty($fan['sex'])) {
				$profile['gender'] = $fan['sex'];
			}
			if(!empty($fan['city'])) {
				$profile['residecity'] = $fan['city'] . '市';
			}
			if(!empty($fan['province'])) {
				$profile['resideprovince'] = $fan['province'] . '省';
			}
			if(!empty($fan['country'])) {
				$profile['nationality'] = $fan['country'];
			}
			if(!empty($fan['headimgurl'])) {
				$profile['avatar'] = rtrim($fan['headimgurl'], '0') . 132;
			}
		}
	}
	$addresss = pdo_getall('mc_member_address', array('uid' => $uid));
}

elseif($do == 'del') {
	$_W['page']['title'] = '删除会员资料 - 会员 - 会员中心';
	if(checksubmit('submit')) {
		if(!empty($_GPC['uid'])) {
			$delete_uids = array();
			foreach ($_GPC['uid'] as $uid) {
				$uid = intval($uid);
				if (!empty($uid)) {
					$delete_uids[] = intval($uid);
				}
			}
			if (!empty($delete_uids)) {
				$tables = array('mc_members', 'mc_card_members', 'mc_card_notices', 'mc_card_notices_unread', 'mc_card_record', 'mc_card_sign_record', 'mc_cash_record', 'mc_credits_recharge', 'mc_credits_record', 'mc_mapping_fans', 'mc_member_address', 'mc_mapping_ucenter');
				foreach ($tables as $key => $value) {
					pdo_delete($value, array('uid' => $delete_uids));
				}
				message('删除成功！', referer(), 'success');
			}
		}
		message('请选择要删除的项目！', referer(), 'error');
	}
}

elseif($do == 'add') {
	if($_W['isajax']) {
		$type = trim($_GPC['type']);
		$data = trim($_GPC['data']);
		if(empty($data) || empty($type)) {
			exit(json_encode(array('valid' => false)));
		}
		$user = pdo_get('mc_members', array($type => $data));

		if(empty($user)) {
			exit(json_encode(array('valid' => true)));
		} else {
			exit(json_encode(array('valid' => false)));
		}
	}
	if(checksubmit('form')) {
		$realname = trim($_GPC['realname']) ? trim($_GPC['realname']) : message('姓名不能为空');
		$mobile = trim($_GPC['mobile']) ? trim($_GPC['mobile']) : message('手机不能为空');
		$user = pdo_get('mc_members', array('mobile' => $mobile));
		if(!empty($user)) {
			message('手机号被占用');
		}
		$email = trim($_GPC['email']);
		if(!empty($email)) {
			$user = pdo_get('mc_members', array('email' => $email));
			if(!empty($user)) {
				message('邮箱被占用');
			}
		}
		$salt = random(8);
		$data = array(
			'uniacid' => $_W['uniacid'],
			'realname' => $realname,
			'mobile' => $mobile,
			'email' => $email,
			'salt' => $salt,
			'password' => md5(trim($_GPC['password']) . $salt . $_W['config']['setting']['authkey']),
			'credit1' => intval($_GPC['credit1']),
			'credit2' => intval($_GPC['credit2']),
			'groupid' => intval($_GPC['groupid']),
			'createtime' => TIMESTAMP,
		);
		pdo_insert('mc_members', $data);
		$uid = pdo_insertid();
		message('添加会员成功,将进入编辑页面', url('site/entry/mc/', array('m' => 'ewei_shopping','act' => 'post','uid' => $uid)), 'success');
	}
}

if($do == 'group') {
	if($_W['isajax']) {
		$id = intval($_GPC['id']);
		$group = $_W['account']['groups'][$id];
		if(empty($group)) {
			exit('会员组信息不存在');
		}
		$uid = intval($_GPC['uid']);
		$member = mc_fetch($uid);
		if(empty($member)) {
			exit('会员信息不存在');
		}
		$credit = intval($group['credit']);
		$credit6 = $credit - $member['credit1'];
		$status = pdo_update('mc_members', array('credit6' => $credit6, 'groupid' => $id), array('uid' => $uid));
		if($status !== false) {
			$openid = pdo_fetchcolumn('SELECT openid FROM ' . tablename('mc_mapping_fans') . ' WHERE acid = :acid AND uid = :uid', array(':acid' => $_W['acid'], ':uid' => $uid));
			if(!empty($openid)) {
				mc_notice_group($openid, $_W['account']['groups'][$member['groupid']]['title'], $_W['account']['groups'][$id]['title']);
			}
			exit('success');
		} else {
			exit('更新会员信息出错');
		}
	}
	exit('error');
}

if($do == 'credit_record') {
	$_W['page']['title'] = '积分日志-会员管理';
	$uid = intval($_GPC['uid']);
	$credits = array(
		'credit1' => '积分',
		'credit2' => '余额'
	);
	$type = trim($_GPC['type']) ? trim($_GPC['type']) : 'credit1';
	$pindex = max(1, intval($_GPC['page']));
	$psize = 50;
	$total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('mc_credits_record') . ' WHERE uid = :uid  AND credittype = :credittype ', array(':uid' => $uid, ':credittype' => $type));
	$data = pdo_fetchall("SELECT r.*, u.username FROM " . tablename('mc_credits_record') . ' AS r LEFT JOIN ' .tablename('users') . ' AS u ON r.operator = u.uid ' . ' WHERE r.uid = :uid  AND r.credittype = :credittype ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize .',' . $psize, array(':uid' => $uid, ':credittype' => $type));
	$pager = pagination($total, $pindex, $psize);
	$modules = pdo_getall('modules', array('issystem' => 0), array('title', 'name'), 'name');
	$modules['card'] = array('title' => '会员卡', 'name' => 'card');
}

if($do == 'credit_stat') {
	$_W['page']['title'] = '积分日志-会员管理';
	$uid = intval($_GPC['uid']);
	$credits = array(
		'credit1' => '积分',
		'credit2' => '余额'
	);
	$type = intval($_GPC['type']);
	$starttime = strtotime('-7 day');
	$endtime = strtotime('7 day');
	if($type == 1) {
		$starttime = strtotime(date('Y-m-d'));
		$endtime = TIMESTAMP;
	} elseif($type == -1) {
		$starttime = strtotime('-1 day');
		$endtime = strtotime(date('Y-m-d'));
	} else{
		$starttime = strtotime($_GPC['datelimit']['start']);
		$endtime = strtotime($_GPC['datelimit']['end']) + 86399;
	}
	if(!empty($credits)) {
		$data = array();
		foreach($credits as $key => $li) {
			$data[$key]['add'] = round(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uid = :uid AND createtime > :start AND createtime < :end AND credittype = :type AND num > 0', array(':uid' => $uid, ':start' => $starttime, ':end' => $endtime, ':type' => $key)),2);
			$data[$key]['del'] = abs(round(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uid = :uid AND createtime > :start AND createtime < :end AND credittype = :type AND num < 0', array(':uid' => $uid, ':start' => $starttime, ':end' => $endtime, ':type' => $key)),2));
			$data[$key]['end'] = $data[$key]['add'] - $data[$key]['del'];
		}
	}
}
include $this->template('member');
	}
	public function doMobileAjaxdelete() {
		global $_GPC;
		$delurl = $_GPC['pic'];
		if (file_delete($delurl)) {
			echo 1;
		} else {
			echo 0;
		}
	}

	public function doMobileOrder() {
		global $_W, $_GPC;

		$orderId = intval($_GPC['orderid']);
		$status = intval($_GPC['status']);
		$referStatus = intval($_GPC['curtstatus']);
		$sql = 'SELECT `id` FROM ' . tablename('shopping_order') . ' WHERE `id` = :id AND `weid` = :weid AND `from_user`
				= :from_user';
		$params = array(':id' => $orderId,  ':from_user' => $_W['fans']['from_user']);
		$orderId = pdo_fetchcolumn($sql, $params);
		$redirect = $this->createMobileUrl('myorder', array('status' => $referStatus));
		if (empty($orderId)) {
			message('订单不存在或已经被删除', $redirect , 'error');
		}

		if ($_GPC['op'] == 'delete') {
			pdo_delete('shopping_order', array('id' => $orderId));
			pdo_delete('shopping_order_goods', array('orderid' => $orderId));
			message('订单已经成功删除！', $redirect, 'success');
		} else {
			pdo_update('shopping_order', array('status' => $status), array('id' => $orderId));
			message('订单已经成功取消！', $redirect, 'success');
		}
	}
	//1608 14:54 wuwenhan //订单评论
	public function doWebOrdercomment(){
		global $_W, $_GPC;
		$id = $_GPC['id'];
		$pindex = max(1, intval($_GPC['page']));
		$psize = 10;

		$status = 1;
		$limit = ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
		$sql = 'SELECT * FROM ' . tablename('shopping_comment') . ' WHERE `orderid` = :id and `status` = :status '. $limit;
		$sqlall = 'SELECT COUNT(*) FROM ' . tablename('shopping_comment') . ' AS `o` WHERE `orderid` = :id';
		$params = array(':id'=>$id,':status'=>$status);

		$total = pdo_fetchcolumn($sqlall, $params);
		$pager = pagination($total, $pindex, $psize);

		$commentlist = pdo_fetchall($sql,$params);
		$this->assign('commentlist',$commentlist);
		include $this->template('ordercomment');
	}
	//160806 14:54 wuwenhan //发送微信模板
	public function doWebOrdersend(){
		global $_W, $_GPC;
		$id = $_GPC['id'];
 		$orders = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$id));
		

	}
	//1608 14:54 wuwenhan //订单评论删除
	public function doWebOrdercommentdelete(){
		global $_W, $_GPC;
		$id = $_GPC['id'];
		$orderid = $_GPC['orderid'];
		//$status = -1;
		 pdo_delete('shopping_comment', array('id' =>$id));
		//pdo_update('shopping_comment', array('status' => $status), array('id' => $id));
		$redirect = $this->createWebUrl('ordercomment', array('id' => $orderid));
		message('评论已经成功删除！', $redirect, 'success');
	}
	//1609 14:54 wuwenhan //微信鉴定分类列表
	public function doMobilejianbaolist(){
		global $_GPC, $_W;
		$title = "专家";
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 6;
		$status = 1;
		$condition = '';
		if($_GPC['category']){
			$condition = " AND pcate = ".$_GPC['category'];
		}
		
		$sql = 'SELECT * FROM ' . tablename('shopping_goods') . '  WHERE `status` = :status   and openid is not null  '.$condition.' Order By displayorder desc LIMIT '.($pindex - 1) * $psize . ',' . $psize;
		$params = array(':status'=>$status);
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_goods') . " WHERE    status = '1' and openid is not null ". $condition);
		$goods = pdo_fetchall($sql, $params);
		foreach($goods as $key=>&$val){
			$val['newthumb'] =tomedia($val['thumb']);
			$val['catename'] = pdo_getcolumn('shopping_category', array('id' => $val['pcate']), 'name');
			$val['mobileurl'] = $this->createMobileUrl('jianbaoxieyi', array('id' => $val['id']));
			$val['zjurl']  = $this->createMobileUrl('zhuanjiadetail', array('id' => $val['id']));
		}
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){
			return json_encode($goods);
			exit;
		}
		$this->assign('goods',$goods);
		include $this->template('jianbaolist');
	}
	//1609 14:54 wuwenhan //微信鉴定协议
	public function doMobilejianbaoxieyi(){
		global $_W, $_GPC;
		$title = "鉴宝";
		$huiyuan =  pdo_fetch("SELECT * FROM ".tablename('mc_members')." WHERE openid = :openid",array('openid'=>$_W['openid']));
		$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid = :openid  and `isuser` = 0 ", array('openid'=>$_W['openid']));
	
		if(!empty($zhuanjia)){
			 header("Content-type: text/html; charset=utf-8");
            echo "<script>alert('你是专家，不需要请他人鉴定！');history.go(-1);</script>";
            exit;
		}

		if(empty($_GPC['id'])){
			 header("Content-type: text/html; charset=utf-8");
            echo "<script>alert('你没有选择专家！');history.go(-1);</script>";
            exit;
		}
		$_SESSION['order']['goodid'] = $_GPC['id'];
		$cfg = $this->module['config'];
		include $this->template('jianbaoxieyi');
	}
	//1609 14:54 wuwenhan //微信图片上传
	public function doMobilejianbaoshangchuan(){
		global $_GPC, $_W;
		$title = "鉴宝";
		if($_W['ispost']){
		
			$images = $_GPC['upimg'];
			$content = $_GPC['content'];
			$image = array();
			foreach ($images as $img){
				$image[] = $img;
				$imagewidth[] =  getimagesize($img)[0];
				$imageheight[] =  getimagesize($img)[1];
			}
			$_SESSION['order']['upimgwidth'] =  serialize($imagewidth);
			$_SESSION['order']['upimgheight'] =  serialize($imageheight);
			$data['images'] = serialize($image);
			$_SESSION['order']['upimg'] =  $data['images'];
			$_SESSION['order']['content'] =  $content;

			
			header("location: " . $this->createMobileUrl('jianbaoconfirm'));
			exit();
		}


		include $this->template('jianbaoshangchuan');
	}
	//1609 14:54 wuwenhan //微信图片重新上传
	public function doMobilejianbaocxshangchuan(){
		global $_GPC, $_W;
		$title = "鉴宝";
		$orderid = $_GPC['orderid'];
		if($_W['ispost']){
		
			$images = $_GPC['upimg'];
			$content = $_GPC['content'];
			$orderid = $_GPC['orderid'];
			$image = array();
			foreach ($images as $img){
				$image[] = $img;
				$imagewidth[] =  getimagesize($img)[0];
				$imageheight[] =  getimagesize($img)[1];
			}
			$data['upimgwidth'] =  serialize($imagewidth);
			$data['upimgheight'] =  serialize($imageheight);
			$data['upimg'] = serialize($image);
			$data['context'] =  $content;
			$data['status']=1;
			pdo_update("shopping_order", $data, array("id" => $orderid));
			$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$orderid));
			$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$order['expert']));
			sendtext($zhuanjia['phone'],3,0,substr($order['uniontid'],8,15));
			$this->send_templete_message($zhuanjia['openid'],3,0,$_W['siteroot']."app/".$this->createMobileUrl('myorder',array('mark'=>1,'status'=>1)),$orderid);
			
			header("location: " . $this->createMobileUrl('myorder',array('mark'=>0,'status'=>1)));
			exit();
		}
		include $this->template('jianbaocxshangchuan');
	}

   //160810 14:54 wuwenhan //微信拍照上传
   public function doMobileImgupload(){
        global $_W, $_GPC;
       $title = "鉴宝";
        load()->func('file');
        $uptypes = array('image/jpg', 'image/png');
        mkdirs("../attachment/images/jianbao/upimg/" . date("Y/m/d"));
        $destination_folder = "../attachment/images/jianbao/upimg/" . date("Y/m/d") . "/";
		$urlpath = "images/jianbao/upimg/" . date("Y/m/d") . "/";
        if (!file_exists($destination_folder)) {
            mkdir($destination_folder);
        }
        if (!empty($_GPC["mediaId"])) {
            $destination = $this->getMediaImg($_GPC["mediaId"], $destination_folder,$urlpath);
        } else {
            $result['success'] = 1;
            return json_encode($result);
        }
        $picurl = $destination;
        $result['picid'] = tomedia($picurl);
        $result['success'] = 0;
        return json_encode($result);
    }
	    public function getAccessToken()
    {
        global $_W;
        $account = $_W['account'];
        if ($this->_accountlevel < 4) {
            if (!empty($this->_account)) {
                $account = $this->_account;
            }
        }
        load()->classs('weixin.account');
        $accObj = WeixinAccount::create($account['acid']);
        $access_token = $accObj->fetch_token();
        return $access_token;
    }
	//160810 14:54 wuwenhan //微信拍照上传
    private function getMediaImg($serverId, $savePath,$urlpath) {
		
		$access_token = $this->getAccessToken();
        load()->func('communication');
        $url="http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=$access_token&media_id=$serverId";
        $resp = ihttp_request($url);
        if(is_error($resp)) {
            load()->func('logging');
            logging_run($resp);
            return $savePath;
        }
        if ($resp['headers']['Content-Type']=="image/png"){
            $ftype="png";
        } else if ($resp['headers']['Content-Type']=="image/jpg") {
            $ftype="jpg";
        } else if ($resp['headers']['Content-Type']=="image/jpeg") {
            $ftype="jpeg";
        } else {
            load()->func('logging');
            logging_run($resp['headers']);
            return $savePath;
        }
		$imgname = time().rand(1,1000);
        $savePath=$savePath.$imgname.".".$ftype;
		$returnPath = $urlpath.$imgname.".".$ftype;
        $local_file=@fopen($savePath,'w');
        if(false!==$local_file){
            if(false!==fwrite($local_file,$resp['content'])){
                fclose($local_file);
            }
        }
        return $returnPath;
    }	

	//1609 14:54 wuwenhan //微信鉴宝选择鉴定方式
	public function doMobilejianbaoconfirm(){
		global $_GPC, $_W;
		$title = "鉴宝";
		$orderdata = [];

		if($_GPC['orderid']){
			$_SESSION['order']['orderid'] = $_GPC['orderid'];
			$_SESSION['order']['chongfuid'] = $_GPC['orderid'];
		}
		$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id ", array('id'=>$_SESSION['order']['orderid']));
		
		if( ($_SESSION['order']['upimg']==$order['upimg']) && ($_SESSION['order']['content'] == $order['context']) &&  (!isset($_SESSION['order']['chongfuid'])) ){
		
		message('不可重复操作！', $this->createMobileUrl('myorder',array('op'=>'daizhifu','status'=>0)), 'success');
		unset($_SESSION['order']['chongfuid']);
		}
		if(!$_SESSION['order']['chongfuid']){
			
			$huiyuan =  pdo_fetch("SELECT * FROM ".tablename('mc_members')." WHERE openid = :openid",array('openid'=>$_W['openid']));
			$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$_SESSION['order']['goodid']));
			$orderdata['zhuanjianame'] = $zhuanjia['title'];
			$orderdata['phone'] = $zhuanjia['phone'];
			$orderdata['expert'] = $_SESSION['order']['goodid'];
			$orderdata['upimg'] = $_SESSION['order']['upimg'] ;
			$orderdata['createtime']= time();
			$orderdata['context'] = $_SESSION['order']['content'];
			$orderdata['status'] = 0;
			$orderdata['upimgwidth'] =	$_SESSION['order']['upimgwidth'] ;
			$orderdata['upimgheight'] = $_SESSION['order']['upimgheight'] ;
			$orderdata['nickname'] = $huiyuan['nickname'];
			$orderdata['mobile'] = $huiyuan['mobile'];
			$orderdata['from_user'] = $_W['openid'];
			$orderdata['zjopenid'] = $zhuanjia['openid'];
			pdo_insert('shopping_order', $orderdata);

			$orderid = pdo_insertid();
			$_SESSION['order']['orderid'] = $orderid;
			$_SESSION['order']['chongfuid'] = $orderid;
		}

		include $this->template('jianbaoconfirm');
	}
	//1609 14:54 wuwenhan //微信鉴宝选择支付方式
	public function doMobilejianbaopay(){
		global $_GPC, $_W;
		$title = "鉴宝";
		$act = trim($_GPC['act']);
		$_SESSION['order']['price'] = $_GPC['paymoney'];
		$_SESSION['order']['fangshi'] = $_GPC['fanshi'];
		$_SESSION['order']['paifangshi'] = $_GPC['paifangshi'];
 		$orderid = $_SESSION['order']['orderid'];

		if(!$_GPC['paymoney']){
			header("location: " . $this->createMobileUrl('jianbaoconfirm',array('orderid'=>$orderid)));
			exit();
		}
		$datasession['price'] =$_GPC['paymoney'];
		$datasession['fangshi'] =$_GPC['fanshi'];
		$datasession['paifangshi'] = $_GPC['paifangshi'];
		$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$_SESSION['order']['goodid']));
		pdo_update("shopping_order", $datasession, array("id" => $orderid));
		

		if($act == 'post_huoqu'){
			$data = array();
			$wOpt = $this->getowpt($zhuanjia['credit'],'请'.$zhuanjia['title'].'鉴宝');
			$data['status'] = 1;
			$data['role'] = 'fans';
			$data['appId'] = $wOpt['appId'];
			$data['timeStamp'] = $wOpt['timeStamp'];
			$data['nonceStr'] = $wOpt['nonceStr'];
			$data['package'] = $wOpt['package'];
			$data['signType'] = $wOpt['signType'];
			$data['paySign'] = $wOpt['paySign'];
			$data['orderid'] = $orderid;
			$datapay['status']=$_SESSION['order']['orderid'];
			
				
			$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id ", array('id'=>$orderid));
			if( ($_SESSION['order']['upimg']==$order['upimg']) && ($_SESSION['order']['content'] == $order['context']) &&  (!isset($_SESSION['order']['chongfuid'])) ){
				$datapay['status']=2;
				$datapay['message'] = "你已支付";
				unset($_SESSION['order']['chongfuid']);
				die(json_encode($datapay));	
			}
			if($order['status'] == 1 || $order['status']==2 || $order['status']==3){
				$datapay['status']=2;
				$datapay['message'] = "你已支付";
				unset($_SESSION['order']['chongfuid']);
				die(json_encode($datapay));
			}
			pdo_update("shopping_order", array('uniontid'=>$wOpt['uniontid']), array("id" => $orderid));
			unset($_SESSION['order']['chongfuid']);
			die(json_encode($data));
			
		}
		if($act == 'post_success'){
			$orderid = intval($_GPC['orderid']);
			$datastatus['status'] = 1; 
			$datastatus['paytime'] = time();
			//鉴定天数
			$newtian = $_SESSION['order']['paifangshi']/8;
			//当天17点
			$end = strtotime(date("Y-m-d 17:00:00",time()));
			$start = strtotime(date("Y-m-d 9:00:00",time()));
			//如果现在时间在范围内容
			if(time()<$end && time()>$start　){
				$aa = $end-time();
			}else{
				$aa = 0;
			}
			$jieshu = array_pop($this->get_days(time(),$newtian));
			$riqi = pdo_fetch("SELECT * FROM ".tablename('shopping_goods_jumpriqi')." WHERE id = :id", array('id'=>1));
			if(isset($riqi['jump'])){
				$arr = explode(',',$riqi['jump']); 
				$arrtwo = $this->get_days(time(),$newtian);
				$jiajia = count(array_intersect($arr,$arrtwo)) ;
				$newtime = array_pop($this->get_days(time(),$newtian));
				$jieshu = date("Y-m-d",strtotime($newtime )+86400*$jiajia);
			}
			$endtime = strtotime($jieshu.' 17:00:00')-$aa;
			$datastatus['paishjian'] = $endtime;//time()+3600*$_SESSION['order']['paifangshi'];
			pdo_update("shopping_order", $datastatus, array("id" => $orderid));
			$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$orderid));
			// sendtext($zhuanjia['phone'],3,0,substr($order['uniontid'],8,15));
			 $this->send_templete_message($zhuanjia['openid'],3,0,$_W['siteroot']."app/".$this->createMobileUrl('myorder',array('mark'=>1,'status'=>1)),$orderid);
			$datares = array();
			$datares['status'] = 1;
			unset($_SESSION['order']['chongfuid']);
			die(json_encode($datares));
		}


		include $this->template('jianbaopay');
	}
	//抛去周六日，获取几天后的
	public function get_days ($date="",$tian)
	{
		$now = empty($date)?time():$date;
		$days = array();
		$i = 1;
		while(count($days)<$tian)
		{
			$timer = $now+3600*24*$i;
			$num= date("N",$timer)-2; //周一开始
			if($num>=-1 and $num<=3)
			{
				$days[]=date("Y-m-d",$now+3600*24*$i);
			}
			$i++;
		}
	
	return $days;
	}
	//调取支付接口
	public function getowpt($credit,$title){
		global $_W;
		load()->model('payment');
		$setting = uni_setting($_W['uniacid'], array('payment'));
		$wechat = $setting['payment']['wechat'];
		if(empty($wechat)){
			$data = array();
			$data['status'] = 0;
			$data['message'] = '微信支付配置错误';
			die(json_encode($data));
		}
		$sql = 'SELECT `key`,`secret` FROM ' . tablename('account_wechats') . ' WHERE `acid`=:acid';
		$row = pdo_fetch($sql, array(':acid' => $wechat['account']));
		$wechat['appid'] = $row['key'];
		$wechat['secret'] = $row['secret'];
		$tid = random(32);
		$uniontid = date('YmdHis').random(8,1);
		$params = array(
			'tid' => $tid,
			'fee' => $credit,
			'user' => $_W['openid'],
			'title' => urldecode($title),
			'uniontid' => $uniontid,
		);
		$wOpt = wechat_build($params, $wechat);
		//插入支付记录表
		$wOpt['tid'] = $tid;
		$wOpt['fee'] = $credit;
		$wOpt['openid'] = $_W['openid'];
		$wOpt['uniontid'] =$uniontid;
		return $wOpt;
	}
	//160806 14:54 wuwenhan //微信专家回复选择
	public function doMobilezjhuifu(){
		global $_GPC, $_W;
		$title = "鉴宝";
		//传orderid
		$orderid = $_GPC['orderid'];
		if(isset($_GPC['yidu2']) && $_GPC['yidu2']==1){
				pdo_update("shopping_order",array('yidu2'=>1), array("id" => $_GPC['orderid']));
		}
		//$orderid = 29;
		$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$orderid));
		if($order['status'] !=1){
			message('你已经回复了该订单了，不用再次回复！');
		}
		$this->assign('orderid',$orderid);
		if($_W['ispost']){
			$data['reson'] =$_GPC['reson'];
			if($data['reson']==1){
				$data['resonname'] ="照片不符合鉴定标准，重新上传";
				sendtext($order['mobile'],2,0,substr($order['uniontid'],8,15));
				$this->send_templete_message($order['from_user'],2,0,$_W['siteroot']."app/".$this->createMobileUrl('myorder',array('mark'=>0,'status'=>-1)),$orderid);
			}
			if($data['reson']==2){
				$data['resonname'] ="该宝物由于各种原因，无法鉴定";
				sendtext($order['mobile'],2,0,substr($order['uniontid'],8,15));
				$this->send_templete_message($order['from_user'],2,0,$_W['siteroot']."app/".$this->createMobileUrl('myorder',array('mark'=>0,'status'=>-1)),$orderid);
			}
			if($data['reson']==3){
				$data['resonname'] ="专家语音回复鉴定结果";
				$data['resonrel'] =$_GPC['rel'];
				$data['iszhengshu'] = $_GPC['kjzs'];
			}
			
			pdo_update("shopping_order", $data, array("id" => $_GPC['orderid']));
			if($data['reson']==1){
				pdo_update("shopping_order",array('status'=>-1), array("id" => $_GPC['orderid']));
				header("location: " . $this->createMobileUrl('myorder',array('mark'=>1,'status'=>1)));
				exit();
			}
			if($data['reson']==2){
				pdo_update("shopping_order",array('status'=>-1), array("id" => $_GPC['orderid']));
				header("location: " . $this->createMobileUrl('myorder',array('mark'=>1,'status'=>2)));
				exit();
			}
			header("location: " . $this->createMobileUrl('zjxzfangshi',array('orderid'=>$_GPC['orderid'])));
			exit();
		}

		include $this->template('zjhuifu');
	}
	//160806 14:54 wuwenhan //微信专家选择回复语音方式
	public function doMobilezjxzfangshi(){
		global $_GPC, $_W;
		$title = "鉴宝";
		
		$orderid = $_GPC['orderid'];
		$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$orderid));
		if($order['status'] !=1){
			message('你已经回复了该订单了，不用再次回复！');
		}
		include $this->template('zjxzfangshi');
	}
	//160806 14:54 wuwenhan //微信专家文字回复
	public function doMobilezjwenzihuifu(){
		global $_GPC, $_W;
		$title = "鉴宝";
		$orderid = $_GPC['orderid'];
		$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$orderid));
		if($order['status'] !=1){
			message('你已经回复了该订单了，不用再次回复！');
		}
		$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$orderid));
		if($_W['ispost']){
			sendtext($order['mobile'],2,0,substr($order['uniontid'],8,15));
			$this->send_templete_message($order['from_user'],2,0,$_W['siteroot']."app/".$this->createMobileUrl('myorder',array('mark'=>0,'status'=>2)),$orderid);
			$data['wenzihuifu'] =$_GPC['wenzihuifu'];
			//huifufangshi的1是文字回复 2是语音回复
			$data['huifufangshi'] = 1;
			$data['status'] = 2;
			$data['resonname'] = '专家文字回复鉴定结果';
			pdo_update("shopping_order", $data, array("id" => $_GPC['orderid']));
			header("location: " . $this->createMobileUrl('myorder',array('mark'=>1,'status'=>2)));
			exit();

		}
		include $this->template('zjwenzihuifu');
	}
	//160806 14:54 wuwenhan //微信专家回复语音
	public function doMobilezjhfyuyin(){
		global $_GPC, $_W;
		$title = "鉴宝";
		$act = trim($_GPC['act']);
		$orderid= $_GPC['orderid'];
		$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$orderid));
		if($order['status'] !=1){
			message('你已经回复了该订单了，不用再次回复！');
		}
		if($act == 'answer'){
			$serverId = trim($_GPC['serverId']);
			$timelong = intval($_GPC['timelong']);
			$orderid = trim($_GPC['orderid']);
			$order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = :id", array('id'=>$orderid));
			sendtext($order['mobile'],2,0,substr($order['uniontid'],8,15));
			$this->send_templete_message($order['from_user'],2,0,$_W['siteroot']."app/".$this->createMobileUrl('myorder',array('mark'=>0,'status'=>2)),$orderid);
			$data = array();
			$media = $this->weixinuploadvoice($serverId);
			$data['openid'] = $_W['openid'];
			$data['voice_id'] = tomedia($media);
			$data['serverid'] = $serverId;
			$data['timelong'] = $timelong;
			$data['orderid'] = $orderid;
			$data['create_time'] = time();

			pdo_insert('shopping_order_voice', $data);
			$ordervoice['id'] = pdo_insertid();

			$token = $this->getAccessToken();
		
			$service_id = $serverId;
			load()->func('communication');
			$url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=".$token."&media_id=".$service_id;
		
			$key = M('qiniu')->fetch($url,$service_id.".amr");
		
			$re_url = $this->createMobileUrl('qiniu2mp3',array('id'=>$ordervoice['id'],'table'=>'shopping_order_voice'));
			$re_url = str_replace('./','',$re_url);
			$re_url = $_W['siteroot'].'app/'.$re_url;
			$return = M('qiniu')->toMp3($key,$re_url);

			pdo_update("shopping_order", array('status'=>2,'huifufangshi'=>2), array("id" => $orderid));

			$data = array();
			$data['status'] = 1;
			$data['message'] = '发送成功';
			die(json_encode($data));

		}
		include $this->template('zjhfyuyin');
	}
	//1609 14:54 wuwenhan //微信专家列表
	public function doMobilezhuanjialist(){
		global $_GPC, $_W;
		$title = "专家";
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 7;
		$status = 1;
		$condition = '';
		if($_GPC['category']){
			$condition = " AND pcate = ".$_GPC['category'];
		}
		
		$sql = 'SELECT * FROM ' . tablename('shopping_goods') . '  WHERE `status` = :status and openid is not null  '.$condition.' Order By displayorder desc LIMIT '.($pindex - 1) * $psize . ',' . $psize;
		$params = array(':status'=>$status);
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_goods') . " WHERE    status = '1' and openid is not null ". $condition);
		$goods = pdo_fetchall($sql, $params);
		foreach($goods as $key=>&$val){
			$val['newthumb'] =tomedia($val['thumb']);
			$val['catename'] = pdo_getcolumn('shopping_category', array('id' => $val['pcate']), 'name');
			$val['mobileurl'] = $this->createMobileUrl('jianbaoxieyi', array('id' => $val['id']));
			$val['zjurl']  = $this->createMobileUrl('zhuanjiadetail', array('id' => $val['id']));
		}
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){
			return json_encode($goods);
			exit;
		}
		$this->assign('goods',$goods);
		include $this->template('zhuanjialist');	
	}
	public function doMobilezhuanjiadetail(){
		global $_GPC, $_W;
		$title = "专家";
		$id = $_GPC['id'];
		$act = trim($_GPC['act']);
		if($act == 'src'){
			$collect =  pdo_fetch("SELECT * FROM ".tablename('shopping_goods_collect')." WHERE openid = :openid and goodid = :goodid", array('openid'=>$_W['openid'],'goodid'=>$id));
			
			if($collect){
				$datacollect = array();
				$shopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$_GPC['id']));
				$shopclass['collect'] -=1;
				pdo_update("shopping_goods", array('collect'=>$shopclass['collect']), array("id" => $_GPC['id']));
				
				pdo_delete('shopping_goods_collect', array('id'=>$collect['id']));
				$datacollect['status'] = 1;
				die(json_encode($datacollect));
			}else{
				$datacollect = array();
				$shopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$_GPC['id']));
				$shopclass['collect'] +=1;
				pdo_update("shopping_goods", array('collect'=>$shopclass['collect']), array("id" => $_GPC['id']));
				$data['goodid'] = $_GPC['id'];
				$data['openid'] = $_W['openid'];
				$data['created_at'] = time();
				pdo_insert('shopping_goods_collect', $data);
				$datacollect['status'] = 2;
				die(json_encode($datacollect));
			}
		}
		$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$id));
		$iscollect = pdo_fetch("SELECT * FROM ".tablename('shopping_goods_collect')." WHERE goodid = :id and openid = :openid", array('id'=>$id,'openid'=>$_W['openid']));
		$comment = pdo_fetchall("SELECT * FROM ".tablename('shopping_comment')." WHERE status=:status and shows=:shows and expertid = :expertid", array('expertid'=>$id,'status'=>1,'shows'=>1));
		//var_dump($comment);
		$class = pdo_fetchall("SELECT * FROM ".tablename('shopping_class')." WHERE openid = :openid", array('openid'=>$zhuanjia['openid']));
		
		include $this->template('zhuanjiadetail');
	}
	//160809 14:54 wuwenhan 后台语音课堂列表
	public function doWebclass(){
		global $_GPC, $_W;
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 20;
	
		$sql = 'SELECT * FROM ' . tablename('shopping_class') . '    Order By ding desc, create_time desc LIMIT '.($pindex - 1) * $psize . ',' . $psize;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_class') . "    ");
	
		$voices = pdo_fetchall($sql, $params);
		$pager = pagination($total, $pindex, $psize);
        if($_GET['delete']){
            $id = intval($_GET['id']);
			$row = pdo_fetch("SELECT id FROM ".tablename('shopping_class')." WHERE id = ".$id);
			if (empty($row)) {
				message('抱歉，课堂语音不存在或是已经被删除！');
			}

			pdo_update("shopping_class", array('status'=>-1), array("id" => $id));
            message('删除成功',$this->createWebUrl('class'),'success');
        }
		include $this->template('class');
	}
	//160809 14:54 wuwenhan 后台语音课堂编辑
	public function doWebclassedit(){
		global $_GPC, $_W;
		$id = intval($_GET['id']);
		$class = pdo_fetch("SELECT * FROM ".tablename('shopping_class')." WHERE id = ".$id);
		if($_W['ispost']){
			$id  =  $_GPC['id'];
			$data['title'] = $_GPC['title'];
			$data['listen_num'] = $_GPC['listen_num'];
			$data['timelong'] = $_GPC['timelong'];
			$data['collect'] = $_GPC['collect'];
			$data['img'] =  M('common')->createImage($_GPC['img']);
			$data['voice_id'] =  M('common')->createVoice($_GPC['voice_id']);
			$data['create_time'] = strtotime($_GPC['create_time']);
			pdo_update("shopping_class", $data, array("id" => $id));
			message('更新成功',$this->createWebUrl('class'),'success');
		}
		include $this->template('classedit');
	}
	//160809 14:54 wuwenhan 后台语音课堂付费人员
	public function doWebclassfufei(){
		global $_GPC, $_W;
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 10;
		$id = intval($_GET['id']);
		$sql = 'SELECT * FROM ' . tablename('shopping_class_order') . ' where status = 1 and classid =:id  Order By  created_at desc LIMIT '.($pindex - 1) * $psize . ',' . $psize;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_class_order') . " where status = 1   ");
	
		$params = array(':id'=>$id);
	
		$classorder = pdo_fetchall($sql, $params);
		$pager = pagination($total, $pindex, $psize);
		
		
		include $this->template('classfufei');

	}
	public function doWebclassheader(){
		global $_GPC, $_W;
		$arm  = $_GPC['arm'] ;
		$filename = $arm; 
		header('Content-type: audio/amr'); 
		//下载显示的名字 
		header('Content-Disposition: attachment; filename="语音试听审核.amr"'); 
		readfile("$filename"); 
		exit(); 
	}
	//160809 14:54 wuwenhan 后台语音课堂审核
	public function doWebclasscheck(){
		global $_GPC, $_W;
		$id = intval($_GET['id']);
		pdo_update("shopping_class", array('status'=>2), array("id" => $id));
		message('审核成功',$this->createWebUrl('class'),'success');
	
	}
	//160810  14:54 wuwenhan //专家录制语音课堂
	public function doMobileluzhiclass(){
		global $_GPC, $_W;
		$title = "录音";
		//传专家id
		$id = intval($_GPC['id']);
		//$id = 5;
		$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$id));
		$act = trim($_GPC['act']);
		if(empty($zhuanjia)){
			 header("Content-type: text/html; charset=utf-8");
            echo "<script>alert('你不是专家，不能录制语音课堂！');history.go(-1);</script>";
            exit;
		}
		if($act == 'answer'){

			$serverId = trim($_GPC['serverId']);
			$timelong = intval($_GPC['timelong']);
			$zhuanjiaid = trim($_GPC['zhuanjiaid']);
			$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$zhuanjiaid));
			$data = array();
			$media = $this->weixinuploadvoice($serverId);
			$data['openid'] = $_W['openid'];
			$data['voice_id'] = tomedia($media);
			$data['serverid'] = $serverId;
			$data['zjname'] = $zhuanjia['title'];
			$data['category'] = $_GPC['category'];
			$data['price'] =$zhuanjia['credit'];
			$data['timelong'] = $timelong;
			$data['status'] = 1;
			$data['create_time'] = time();
			$data['title'] = $_GPC['title'];
			$data['isweixin'] = 1;
			$data['img'] = $zhuanjia['avatar'];
			pdo_insert('shopping_class', $data);
			$shopclass['id'] = pdo_insertid();

			$token = $this->getAccessToken();
		
			$service_id = $serverId;
			load()->func('communication');
			$url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=".$token."&media_id=".$service_id;
		
			$key = M('qiniu')->fetch($url,$service_id.".amr");
		
			$re_url = $this->createMobileUrl('qiniu2mp3',array('id'=>$shopclass['id'],'table'=>'shopping_class'));
			$re_url = str_replace('./','',$re_url);
			$re_url = $_W['siteroot'].'app/'.$re_url;
			$return = M('qiniu')->toMp3($key,$re_url);
		//	M('common')->createAudio('shopping_class',$shopclass['id'],$serverId);
			$data = array();
			
			$data['message'] = '发送成功';
			die(json_encode($data));

		}
		include $this->template('luzhiclass');
	}

	public function doMobileqiniu2mp3(){
	    global $_W,$_GPC;
		$table = trim($_GPC['table']);
		$id = trim($_GPC['id']);
	
		$__input = $_GPC['__input'];
		$item = $__input['items'][0];
		$key = $item['key'];
		$items['src'] = M('qiniu')->getUrl($key);
		pdo_update($table, $items, array("id" => $id));
		// M("".$table)->update($items);

	}

	//160808 14:54 wuwenhan //微信语音课堂
	public function doMobileyiclass(){
		global $_GPC, $_W;
		$title = "语音课堂";
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 6;
		$status = 2;

		if($_GPC['category']){
			$condition = " AND category = ".$_GPC['category'];
		}
$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid = :openid and isuser = 0", array('openid'=>$_W['openid']));

		$sql = 'SELECT * FROM ' . tablename('shopping_class') . '  WHERE `status` = :status '.$condition.'  Order By ding desc, create_time desc LIMIT '.($pindex - 1) * $psize . ',' . $psize;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_class') . " WHERE    status = '2' ".$condition." ");
		$params = array(':status'=>$status);
		$voices = pdo_fetchall($sql, $params);
		$pager = pagination($total, $pindex, $psize);
		foreach($voices as $key=>&$val){
			$zhuanjiaxianshi = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid = :openid", array('openid'=>$val['openid']));
			$voice = pdo_fetch("SELECT * FROM ".tablename('shopping_class_order')." WHERE toopenid = :openid and classid = :classid and status = 1", array('openid'=>$_W['openid'],'classid'=>$val['id']));
			$val['yanse'] = !empty($voice) ? '#9f625a':'#74090a';
			$val['upzjname'] = $zhuanjiaxianshi['title'];
			$val['upimg'] = $zhuanjiaxianshi['avatar'];
			$val['createtime'] = date('Y-m-d H:i:s',$val['create_time']);
			$val['url'] = $this->createMobileUrl('yiclassdetail', array('id' => $val['id']));
			$val['money'] = $val['ding']==1? "免费" : $val['price'].'元';
		}
		if($_W['ispost']){
			return json_encode($voices);
			exit;
		}
		
		include $this->template('yiclass');
	}
	//160810 14:54 wuwenhan //微信专家语音课堂
	public function doMobilezjyiclass(){
		global $_GPC, $_W;
	$title = "我的语音课堂";
		$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid = :openid", array('openid'=>$_W['openid']));
	

		if( $zhuanjia){
				$pindex = max(1, intval($_GPC["page"]));
				$psize = 6;
				$status = 1;
				$openid = $_W['openid'];
				$sql = 'SELECT * FROM ' . tablename('shopping_class') . '  WHERE `status` >= :status and `openid` = :openid  Order By ding desc, create_time desc LIMIT '.($pindex - 1) * $psize . ',' . $psize;
				$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_class') . " WHERE  status >= :status and  openid = :openid ",array('openid'=>$openid,'status'=>1));
				$params = array('status'=>1,':openid'=>$openid);
				$voices = pdo_fetchall($sql, $params);
			
				$pager = pagination($total, $pindex, $psize);
				foreach($voices as $key=>&$val){
					$voice = pdo_fetch("SELECT * FROM ".tablename('shopping_class_order')." WHERE toopenid = :openid and classid = :classid and status = 1", array('openid'=>$_W['openid'],'classid'=>$val['id']));
					$val['yanse'] = !empty($voice) ? '#9f625a':'#74090a';
					$val['upzjname'] = $zhuanjia['title'];
					$val['upimg'] = $zhuanjia['avatar'];
					$val['createtime'] = date('Y-m-d H:i:s',$val['create_time']);
					$val['url'] = $this->createMobileUrl('yiclassdetail', array('id' => $val['id'],'wode'=>1));
				}
				if($_W['ispost']){
					return json_encode($voices);
					exit;
				}
				include $this->template('zjyiclass');
		}else{
			header("location: " . $this->createMobileUrl('member',array('done'=>1)));
			exit();
		}
	
	}
	//160810 14:54 wuwenhan //微信会员语音课堂
	public function doMobilehyyiclass(){
		global $_GPC, $_W;
 		$title = "我的语音课堂";
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 6;
		$status = 1;
		$openid = $_W['openid'];
	
		$huiyuan = pdo_fetchall("SELECT * FROM ".tablename('shopping_class_order')." WHERE status = :status and toopenid = :toopenid", array('status'=>$status,'toopenid'=>$openid));
		
		$newarr = [];
		foreach($huiyuan as $key=>$val){
			array_push($newarr, $val['classid']);
		}

		if(!empty($newarr)){
			$sql = 'SELECT * FROM ' . tablename('shopping_class') . '  WHERE   `id` in ('.implode(',',$newarr).')  Order By ding desc, create_time desc LIMIT '.($pindex - 1) * $psize . ',' . $psize;
			$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('shopping_class') . " WHERE    id in (".implode(',',$newarr).") ");
			
			$params = array(':status'=>$status);
			$voices = pdo_fetchall($sql, $params);
		
			$pager = pagination($total, $pindex, $psize);
		}
	
		foreach($voices as $key=>&$val){
			$voice = pdo_fetch("SELECT * FROM ".tablename('shopping_class_order')." WHERE toopenid = :openid and classid = :classid and status = 1", array('openid'=>$_W['openid'],'classid'=>$val['id']));
			$val['yanse'] = !empty($voice) ? '#9f625a':'#74090a';
			$val['createtime'] = date('Y-m-d H:i:s',$val['create_time']);
			$val['url'] = $this->createMobileUrl('yiclassdetail', array('id' => $val['id'],'wode'=>1));
		}
		if($_W['ispost']){
			return json_encode($voices);
			exit;
		}
		include $this->template('hyyiclass');	
	}
	//160808 14:54 wuwenhan //微信语音课堂详情页
	public function doMobileyiclassdetail(){//5555
		global $_GPC, $_W;
		$huiyuan =  pdo_fetch("SELECT * FROM ".tablename('mc_members')." WHERE openid = :openid",array('openid'=>$_W['openid']));
		$zhuanjia = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid = :openid and `isuser` = 0 ", array('openid'=>$_W['openid']));
		if($_GPC['wode']==1){
	$title = "我的语音课堂";
		}elseif($_GPC['sc']==1){
			$title="我的收藏的语音课堂";
		}else{
			$title = "语音课堂";
		}

		if($zhuanjia || $huiyuan){
			
		$voicesid = $_GPC['id'];
		$collecttrue =  pdo_fetch("SELECT * FROM ".tablename('shopping_class_collect')." WHERE openid = :openid and classid = :classid", array('classid'=>$voicesid,'openid'=>$_W['openid']));
		$act = trim($_GPC['act']);
		$voice = pdo_fetch("SELECT * FROM ".tablename('shopping_class')." WHERE id = :id", array('id'=>$voicesid));	
		$zhuanjiaxianshi = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid = :openid", array('openid'=>$voice['openid']));

		if($act == 'collect'){
			$collect =  pdo_fetch("SELECT * FROM ".tablename('shopping_class_collect')." WHERE openid = :openid and classid = :classid", array('openid'=>$_W['openid'],'classid'=>$_GPC['id']));
			$huiyuan =  pdo_fetch("SELECT * FROM ".tablename('mc_members')." WHERE openid = :openid",array('openid'=>$_W['openid']));
			if($collect){
				$datacollect = array();
				$shopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_class')." WHERE id = :id", array('id'=>$_GPC['id']));
				$shopclass['collect'] -=1;
				pdo_update("shopping_class", array('collect'=>$shopclass['collect']), array("id" => $_GPC['id']));
				$newshopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_class')." WHERE id = :id", array('id'=>$_GPC['id']));
				$datacollect['collect'] =$newshopclass['collect'];
				pdo_delete('shopping_class_collect', array('id'=>$collect['id']));
				$datacollect['status'] = 1;
				$datacollect['tu'] = 'Z_flt';
				die(json_encode($datacollect));
			}else{
				$incollect['classid'] = $_GPC['id'];
				$incollect['openid'] = $_W['openid'];
				$incollect['nickname'] =isset($huiyuan['nickname'])?$huiyuan['nickname']:$zhuanjia['title'];
				$incollect['created_at'] = time();
				pdo_insert('shopping_class_collect', $incollect);
				$shopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_class')." WHERE id = :id", array('id'=>$_GPC['id']));
				$shopclass['collect'] +=1;
				pdo_update("shopping_class", array('collect'=>$shopclass['collect']), array("id" => $_GPC['id']));
				$datacollect['status'] = 2;
				$newshopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_class')." WHERE id = :id", array('id'=>$_GPC['id']));
				$datacollect['collect'] =$newshopclass['collect'];
				$datacollect['tu'] = 'Z_flta';
				die(json_encode($datacollect));
			}
			
		}
		if($act == 'src'){

			$voicesid = $_GPC['id'];
			$openid = $_W['openid'];
			$voice = pdo_fetch("SELECT * FROM ".tablename('shopping_class')." WHERE id = :id", array('id'=>$voicesid));
			$voice_order = pdo_fetch("SELECT * FROM ".tablename('shopping_class_order')." WHERE classid = :classid and status = :status and toopenid = :toopenid", array('status'=>'1','toopenid'=>$openid,'classid'=>$voicesid));	
			$voice['listen_num'] +=1;
			pdo_update("shopping_class", array('listen_num'=>$voice['listen_num']), array("id" => $voicesid));
			
			//专家自己点击或者已交费点击
			if($voice_order || ($openid == $voice['openid'])){
			
				$data = array();
				$data['status'] = 1;
				die(json_encode($data));
			}else{
				//未交费点击
			if($zhuanjia){
				$data = array();
				$data['status'] = 2;
				die(json_encode($data));	
			}
				$data = array();
				$data['status'] = 0;
				$zhuanjiafei = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid = :openid", array('openid'=>$voice['openid']));
				$wOpt = $this->getowpt($zhuanjiafei['credit'],'专家语音课堂支付'.$voice['title']);
				$data['role'] = 'fans';
				$data['appId'] = $wOpt['appId'];
				$data['timeStamp'] = $wOpt['timeStamp'];
				$data['nonceStr'] = $wOpt['nonceStr'];
				$data['package'] = $wOpt['package'];
				$data['signType'] = $wOpt['signType'];
				$data['paySign'] = $wOpt['paySign'];
				$havevoice = pdo_fetch("SELECT * FROM ".tablename('shopping_class_order')." WHERE classid = :classid and toopenid= :openid", array('classid'=>$voicesid,'openid'=>$openid));
				if($havevoice){
					$data['orderid'] = $havevoice['id'];
				}else{
					$classorder = array(
						'classid'   => $voicesid,
						'toopenid' 	=> $openid,
						'created_at' => date('Y-m-d h:i:s',time()),
						'status' => 0,
						'uniontid'=>$wOpt['uniontid'],
					);
					
					pdo_insert('shopping_class_order', $classorder);
					$data['orderid'] = pdo_insertid();
				}

		
				die(json_encode($data));

			}

			
		}
			if($act == 'paySuccess'){
				$orderid = intval($_GPC['orderid']);
				$datastatus['status'] = 1; 
				pdo_update("shopping_class_order", $datastatus, array("id" => $orderid));
				$datares = array();
				$datares['status'] = 1;
				die(json_encode($datares));
			}
		include $this->template('yiclassdetail');	
		}else{
			message('你还没有注册，请先注册！', $this->createMobileUrl('member'), 'success');
			exit();
		}
	

	}
	//
	public function doWebqiniuset(){
		global $_GPC, $_W;
		 $item = pdo_fetch("SELECT * FROM ".tablename('shopping_qiniuset')." WHERE id = 1");
		if($_W['ispost']){
           
            $data = array(
                'access_key'       => $_POST['access_key'],
                'secret_key'       => $_POST['secret_key'],
                'bucket'     => $_POST['bucket'],
                'bucket_result' => $_POST['bucket_result'],
                'url' => $_POST['url'],
                'mps'  => $_POST['mps'],
            );
                pdo_update('shopping_qiniuset', $data,array('id'=>1));
                message('保存成功',$this->createWebUrl('qiniuset'),'success');
		}
		include $this->template('qiniuset');
	}
	public function doWebtaskplan(){
         global $_W,$_GPC;
		 $order = pdo_fetchall("SELECT * FROM ".tablename('shopping_order')." WHERE status =:status",array(":status" => 1));
		 $smssetting = pdo_fetch("SELECT * FROM ".tablename('shopping_sendSMSsetting')." WHERE id =:id",array(":id" => 1));
		 $opensetting = pdo_fetch("SELECT * FROM ".tablename('shopping_sendwechatsetting')." WHERE id =:id",array(":id" => 1));
		 foreach($order as $key=>$val){
	
			 if(countdown($val['id'])){

				$this->send_templete_message($val['zjopenid'],4,0,$_W['siteroot']."app/".$this->createMobileUrl('myorder',array('mark'=>1,'status'=>1)),$val['id']);
				$this->send_templete_message($opensetting['seropenid'],5,0,$_W['siteroot'],$val['id']);
				sendtext($val['phone'],4,$val['zhuanjianame'],substr($val['uniontid'],8,15));
				
			
				$this->sendtext($smssetting['phone'],5,$val['zhuanjianame'],substr($val['uniontid'],8,15));
	
				WeUtility::logging('taskplan', var_export($smssetting['phone'], true));
				WeUtility::logging('taskplan', var_export($opensetting['seropenid'], true));
				WeUtility::logging('taskplan', var_export($val['id'], true));
			 }
			 if(timesup($val['id'])){

				// pdo_update("shopping_order", array('reson'=>2,'status'=>-1), array("id" => $val['id']));
				 sendtext($smssetting['phone'],8,$val['zhuanjianame'],substr($val['uniontid'],8,15));
				$this->send_templete_message($opensetting['seropenid'],8,0,$_W['siteroot'],$val['id']);
				WeUtility::logging('taskplan', var_export($val['id'], true));
				WeUtility::logging('taskplan', var_export($opensetting['seropenid'], true));
			 }
		 }
		 echo "success";
	
	}
	//160804 14:54 wuwenhan //微信发送模板  保留新增部分 zsn 160812 15:12
	public function send_templete_message($openid,$templateid,$data,$url,$orderid){
		global $_W,$_GPC;
		load()->model('mc');
        $acc = mc_notice_init();
		if (is_error($acc)) {
            return error(-1, $acc['message']);
        }
        // $data = array('first' => array('value' => $title, 'color' => '#ff510'), 'keyword1' => array('value' => $task_type, 'color' => '#ff510'), 'keyword2' => array('value' => $task_order, 'color' => '#ff510'), 'keyword3' => array('value' => $time, 'color' => '#ff510'), 'keyword3' => array('value' => $finish_time, 'color' => '#ff510'), 'remark' => array('value' => $remark, 'color' => '#ff510'));
		$item = pdo_fetch("SELECT * FROM ".tablename('shopping_sendwechatsetting')." WHERE id = 1");
        $order = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id =:id",array(":id" => $orderid));
        $from_user = $order['from_user'];
        $expertinfo = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid =:openid",array(":openid" => $from_user));
        if($templateid == 2){             //鉴定结果通知会员
            $templateid = $item['resulttp'];
            $data = array(
                'first'    => array('value' => $item['first1'], 'color' => '#ff510'), 
                'keyword1' => array('value' => $order['uniontid'], 'color' => '#ff510'),        //订单号
                'keyword2' => array('value' => date('Y-m-d H:i:s', TIMESTAMP), 'color' => '#ff510'),       //时间
                'remark'   => array('value' => $item['remark1'], 'color' => '#ff510')
            );
        }elseif($templateid == 3){        //鉴宝新订单通知专家
            $templateid = $item['newordertp'];
            $data = array(
                'first'    => array('value' => $item['first2'], 'color' => '#ff510'), 
                'keyword1' => array('value' => $order['uniontid'], 'color' => '#ff510'),        //订单号
                'keyword2' => array('value' => date('Y-m-d H:i:s', TIMESTAMP), 'color' => '#ff510'),       //时间
                'remark'   => array('value' => $item['remark2'], 'color' => '#ff510')
            );
        }elseif($templateid == 4){        //鉴定即将过期通知专家
            $templateid = $item['expoutofdatetp'];
            $dingdan = "订单号：".$order['uniontid'];
            $deadtime = TIMESTAMP + 6*3600;
            $deadline = date('Y-m-d H:i:s', $deadtime);
            $data = array(
                'first'    => array('value' => $item['first3'], 'color' => '#ff510'), 
                'keyword1' => array('value' => $dingdan, 'color' => '#ff510'),        //订单号
                'keyword2' => array('value' => $deadline, 'color' => '#ff510'),       //时间
                'remark'   => array('value' => $item['remark3'], 'color' => '#ff510')
            );
        }elseif($templateid == 5){        //鉴定即将过期通知客服
            $templateid = $item['seroutofdatetp'];
            $deadtime = TIMESTAMP + 6*3600;
            $deadline = date('Y-m-d H:i:s', $deadtime);
            //专家信息
            $item = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id =:id",array(":id" => $orderid));
            $zjopenid = $item['zjopenid'];
            $expert = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid =:openid",array(":openid" => $zjopenid));
            $content = $expert['title']."专家的".$order['uniontid']."订单";
            $data = array(
                'first'    => array('value' => $item['first4'], 'color' => '#ff510'), 
                'keyword1' => array('value' => $content, 'color' => '#ff510'),        //订单号
                'keyword2' => array('value' => $deadline, 'color' => '#ff510'),       //时间
                'remark'   => array('value' => $item['remark4'], 'color' => '#ff510')
            );
        }elseif($templateid == 6){        //鉴宝申请证书通知客服
            $templateid = $item['certificatetp'];
            $data = array(
                'first'    => array('value' => $item['first5'], 'color' => '#ff510'), 
                'keyword1' => array('value' => $order['uniontid'], 'color' => '#ff510'),        //订单号
                'keyword2' => array('value' => date('Y-m-d H:i:s', TIMESTAMP), 'color' => '#ff510'),       //时间
                'remark'   => array('value' => $item['remark5'], 'color' => '#ff510')
            );
        }elseif($templateid == 7){        //鉴宝需退款通知客服
            $templateid = $item['refundtp'];
            $tempmoney = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id =:id",array(":id" => $orderid));
            $money = $tempmoney['price'];
            $data = array(
                'first'    => array('value' => $item['first6'], 'color' => '#ff510'), 
                'keyword1' => array('value' => $order['uniontid'], 'color' => '#ff510'),        //订单号
                'keyword2' => array('value' => $money, 'color' => '#ff510'),       //时间
                'remark'   => array('value' => $item['remark6'], 'color' => '#ff510')
            );
        }elseif($templateid == 8){        //鉴宝超时通知客服
            $templateid = $item['overtimetp'];
            $item['remark7'] = str_replace("*",$expertinfo['title'],$item['remark7']);
            $data = array(
                'first'    => array('value' => $item['first7'], 'color' => '#ff510'), 
                'keyword1' => array('value' => $order['uniontid'], 'color' => '#ff510'),        //订单号
                'keyword2' => array('value' => date('Y-m-d H:i:s', TIMESTAMP), 'color' => '#ff510'),       //时间
                'remark'   => array('value' => $item['remark7'], 'color' => '#ff510')
            );
        }elseif($templateid == 9){        //鉴宝"重要"通知客服
            $templateid = $item['important'];
            $item['remark8'] = str_replace("*",$expertinfo['title'],$item['remark8']);
            $data = array(
                'first'    => array('value' => $item['first8'], 'color' => '#ff510'), 
                'keyword1' => array('value' => $order['uniontid'], 'color' => '#ff510'),        //订单号
                'keyword2' => array('value' => date('Y-m-d H:i:s', TIMESTAMP), 'color' => '#ff510'),       //时间
                'remark'   => array('value' => $item['remark8'], 'color' => '#ff510')
            );
        }
        $status = $acc->sendTplNotice($openid, $templateid, $data, $url);

        return $status;

	}

	public function weixinuploadvoice($media){
		$token = $this->getAccessToken();
		

        load()->func('communication');
        $url="http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=$token&media_id=$media";
        $response = ihttp_request($url);
		if(!empty($response['headers']['Content-disposition']) && strexists($response['headers']['Content-disposition'], $media['media_id'])){
			global $_W;
			$filename =str_replace( array('attachment; filename=', '"',' '),'',$response['headers']['Content-disposition']);
			$filename = "audios/jianbao/".date('Y/m/d')."/".time()."_".random(6).".".$filename;
			load()->func('file');
			file_write($filename, $response['content']);
			file_remote_upload($filename);
			return $filename;
			
		} else {
			$response = json_decode($response['content'], true);
			return error($response['errcode'], $response['errmsg']);
		}
		
	}
	//会员中心
	public function doMobilemember(){
		global $_W,$_GPC;
        $openid = $_W['openid'];
        $login = trylogin($openid);
        if(is_array($login)){
            $user = trylogin($openid);
        }else{
            $user = 0;
        }
        if($user){
            $this->assign('user',$user);
            $pcate = $user['pcate'];
            $zjxinxi=pdo_fetch("select name from ".tablename('shopping_category')." where id='".$pcate."'");
            //单独回复留言
            $middlemsg = pdo_fetchall("SELECT * FROM ".tablename('shopping_contactservice')."WHERE openid = "."'".$_W['openid']."'"." ORDER BY createtime DESC");
            $num = count($middlemsg);
            $yidutotal = pdo_fetchcolumn("select count(*) from".tablename('shopping_message')." where openid='".$_W['openid']."' and status=1");
			$ztotal     = pdo_fetchcolumn("select count(*) from ".tablename('imeepos_fvoice_news')." where class_id = '3' ") + $num;
			$total   = $ztotal - $yidutotal;
			if($_GPC['mark'])
        	{
        		$user['mark']==$_GPC['mark'];
        	}
			if($user['mark']==0)
			{
				//会员待鉴定未读消息
            	$djianding = pdo_fetch("select id from " .tablename('shopping_order')." where from_user='".$_W['openid']."' and status=1");
            	if(!empty($djianding['id']))
            	{
            		$wdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where from_user='".$_W['openid']."' and status=1");
            	}
            	//会员已鉴定未读数
            	$zjjianding = pdo_fetch("select id from " .tablename('shopping_order')." where from_user='".$_W['openid']."' and status>=2");
            	if(!empty($zjjianding['id']))
            	{
            		$yjdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where from_user='".$_W['openid']."' and status>=2 and yjd= '0' ");
            	}
            	//会员无法鉴定未读数
            	$zjwfjd = pdo_fetch("select id from " .tablename('shopping_order')." where from_user='".$_W['openid']."' and status=-1");
            	if(!empty($zjwfjd['id']))
            	{
            		$wfjdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where from_user='".$_W['openid']."' and status=-1 and wfjd= '0' ");
            	}

            	//鉴宝待支付总数 cqn
				$jbdzf = pdo_fetchcolumn("select count(*) from " .tablename('shopping_order')."where status=0 and from_user='".$_W['openid']."'");
				//证书待支付总数 cqn
				$zsdzf = pdo_fetchcolumn("select count(*) from " .tablename('shopping_certificate')."where status=0 and openid='".$_W['openid']."'");
           		$dzftotal = $jbdzf + $zsdzf;

           		//会员我的证书小点和数字
            	$mcerttotal = pdo_fetchcolumn("select count(*) from " .tablename('shopping_certificate'). " where openid='".$_W['openid']."' and status>=1 and status<3");

				//会员未读数总数
				$ztotal = $wdtotal + $yjdtotal + $wfjdtotal + $dzftotal + $mcerttotal;
			}
			else
			{
				//专家待鉴定未读消息
        		$djianding = pdo_fetch("select id from " .tablename('shopping_order')." where zjopenid='".$_W['openid']."' and (status=1 or reson=1)");
            	if(!empty($djianding['id']))
            	{
            		
            		$wdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where zjopenid='".$_W['openid']."' and (status=1 or reson=1)");
            	}
            	//专家已鉴定未读消息
        		$zjjianding = pdo_fetch("select id from " .tablename('shopping_order')." where zjopenid='".$_W['openid']."' and (status>=2 or reson=2)");
            	if(!empty($zjjianding['id']))
            	{
            		
            		$yjdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where zjopenid='".$_W['openid']."' and zjyjd=0 and (status>=2 or reson=2)");
            	}
            	//专家我的证书小点和数字
            	$zcerttotal = pdo_fetchcolumn("select count(*) from " .tablename('shopping_certificate'). " where zjopenid='".$_W['openid']."' and status>=1 and status<3");
            	//专家未读数总数
				$ztotal = $wdtotal+$yjdtotal+$zcerttotal;
			}
			$title ="个人中心";
            include $this->template('member',array('mark'=>$user['mark']));
        }else{
            if($_GET['done']){
                $done = 1;
                include $this->template('register');
            }else{
                $done = 0;
                include $this->template('register');
            }
        }
	}


   //点会员头像进入的页面
	public function doMobilecenter(){
		global $_W,$_GPC;
        $openid = $_W['openid'];
        $login = trylogin($openid);
        if(is_array($login)){
            $user = trylogin($openid);
        }else{
            $user = 0;
        }
        if($user){
            $this->assign('user',$user);
            $title = "个人信息";
            include $this->template('center',array('mark'=>$user['mark']));
        }else{
            include $this->template('register');
        }

	}


	//会员中心修改昵称
	public function doMobilenickname(){
		global $_W, $_GPC;
		if($_POST)
		{
			$nickname = $_POST['name'];
			$mark = $_GET['mark'];
			if($_GET['mark']==0)
        	{
        		$data = pdo_update('mc_members', array('nickname' => $nickname), array('openid' => $_W['openid'])); 
        	}
        	else
        	{
        		$data = pdo_update('shopping_goods', array('nickname' => $nickname), array('openid' => $_W['openid']));
        	}
        	if($data)
        	{
        		echo 1;
        		exit;
        	}

		}
		echo '0';

	}
		//会员中心修改头像
	public function doMobiletouxiang(){
		global $_W, $_GPC;
		load()->func('file');
	    $uptypes = array('image/jpg', 'image/png');
	    mkdirs("../attachment/images/jianbao/upimg/" . date("Y/m/d"));
	    $destination_folder = "../attachment/images/jianbao/upimg/" . date("Y/m/d") . "/";
		$urlpath = "images/jianbao/upimg/" . date("Y/m/d") . "/";
	    if (!file_exists($destination_folder)) {
	        mkdir($destination_folder);
	    }
	    if (!empty($_GPC["mediaId"])) {
	        $destination = $this->getMediaImg($_GPC["mediaId"], $destination_folder,$urlpath);
	    } else {
	       $result['success'] = 1;
	       return json_encode($result);
	    }
	    $picurl = $destination;
	    $touxiang = tomedia($picurl);
	    if($_GPC['mark']==0)
        {
        	$data = pdo_update('mc_members', array('avatar' => $touxiang), array('openid' => $_W['openid'])); 
        }
        else
        {
        		
        	$data = pdo_update('shopping_goods', array('avatar' => $touxiang), array('openid' => $_W['openid']));
        }
	    $result['picid'] = tomedia($picurl);
	    $result['success'] = 0;
        return json_encode($result);
		include $this->template('touxiang');

	}
	//会员中心手机号
	public function doMobilemobile(){
		global $_W, $_GPC;
		if($_POST)
		{
			$mobile = $_POST['mobile'];
			$mark = $_GET['mark'];
			if($_GET['mark']==0)
        	{
        		$data = pdo_update('mc_members', array('mobile' => $mobile), array('openid' => $_W['openid'])); 
        	}
        	else
        	{
        		$data = pdo_update('shopping_goods', array('phone' => $mobile), array('openid' => $_W['openid']));
        	}
        	if($data)
        	{
        		echo 1;
        		exit;
        	}

		}
		echo '0';
	}

	//会员中心我的地址 2016/8/15 cqn
	public function doMobileadress(){
		global $_W, $_GPC;
		$pindex = max(1, intval($_GPC["page"]));
		//var_dump($_GPC['page']);
		$psize = 8;
		$status = 1;
		$sql = "select * from".tablename('mc_member_address')."where openid='".$_W['openid']."' order by id desc LIMIT ".($pindex - 1) * $psize . ',' . $psize;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_member_address') . " WHERE     openid='".$_W['openid']."' order by id desc ");
		$adress = pdo_fetchall($sql, $params);
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){
			return json_encode($adress);
			exit;
		}
		if($_GPC['zszfdz'])
		{
			$zszfdz = 1;
		}
		//var_dump($adress);
		$this->assign('adress',$adress);
		include $this->template('adress');

	}
	//会员中心我的消息列表 2016/8/15 cqn
	public function doMobilemessage(){
		global $_W, $_GPC;
		$pindex = max(1, intval($_GPC["page"]));
		//var_dump($_GPC['page']);
		$psize = 8;
		$status = 1;
        //单独回复留言
        $middlemsg = pdo_fetchall("SELECT * FROM ".tablename('shopping_contactservice')."WHERE openid = "."'".$_W['openid']."'"." ORDER BY createtime DESC");
        $i=0;
        $num = count($middlemsg);
        //系统消息
		$sql = "select * from".tablename('imeepos_fvoice_news')."where class_id='3' order by id desc LIMIT ".($pindex - 1) * $psize . ',' . $psize;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('imeepos_fvoice_news') . " WHERE   class_id='3' ORDER BY createtime DESC")+$num;
		$message = pdo_fetchall($sql, $params);
        if(empty($_W['ispost'])){
            while($i < $num){
                $middlemsg[$i]['title'] = $middlemsg[$i]['replytitle'];
                $middlemsg[$i]['content'] = $middlemsg[$i]['reply'];
                $middlemsg[$i]['createtime'] = $middlemsg[$i]['createtime'];
                
                $message[] = $middlemsg[$i];
                $i++;
            }
        }
		foreach($message as $key=>$val){
            //print_r($val['id']);die('aa');
			$item = pdo_fetch("SELECT status FROM ".tablename('shopping_message')." WHERE newid = '".$val['id']."' and openid='".$_W['openid']."'");
            //print_r($item);die('aa');
			$message[$key]['status'] = $item['status'];
			$message[$key]['url']  = $this->createMobileUrl('messagedetail', array('id' => $val['id']));
			$lens = strlen($val['title'])/3; 
			$message[$key]['title']=mb_substr($val['title'],0,48,'utf-8');
			$message[$key]['createtime']=date('Y-m-d H:i',$val['createtime']);
			if($lens >30)
			{
				$message[$key]['title']=mb_substr($val['title'],0,48,'utf-8').'...';
			} 
		}
		//var_dump($message);
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){
			return json_encode($message);
			exit;
		}
		//var_dump($message);
        //print_r($message);die('aa');
        $title = "我的消息";
		include $this->template('message');

	}

	//会员中心我的消息详情页
	public function doMobilemessagedetail(){
		global $_W, $_GPC;
		$item = pdo_fetch("SELECT * FROM ".tablename('imeepos_fvoice_news')." WHERE id = '".$_GPC['id']."'");
        $middlemsg = pdo_fetch("SELECT * FROM ".tablename('shopping_contactservice')."WHERE id = ".$_GPC['id']." and openid = "."'".$_W['openid']."'"." ORDER BY createtime DESC");
        $middlemsg['title'] = $middlemsg['replytitle'];
        $middlemsg['contents'] = $middlemsg['content'];
        $middlemsg['content'] = $middlemsg['reply'];
        $middlemsg['uniquemsg'] = 1;
        if(!empty($middlemsg['title'])&&!empty($middlemsg['content'])){
            $item = $middlemsg;
            $data = array(
				'hit'      => 1
				);
		      pdo_update('shopping_contactservice',$data,array('id' => $_GPC['id']));
        }
        
		$items = pdo_fetch("SELECT id FROM ".tablename('shopping_message')." WHERE newid = '".$_GPC['id']."' and openid='".$_W['openid']."' ");
		if($_GPC['id'] && empty($items['id']))
		{	
			$data = array(
				'newid'      => $_GPC['id'],
				'openid'     => $_W['openid'],
				'status'      => 1
				);
		      pdo_insert('shopping_message', $data);
		}
		/*$yidutotal = pdo_fetchcolumn("select count(*) from".tablename('shopping_message')." where openid='".$_W['openid']."' and status=1");
		$total     = pdo_fetchcolumn("select count(*) from ".tablename('imeepos_fvoice_news')." where class_id = '3' ");
		$wdtotal   = $total - $yidutotal;*/
		//var_dump($item);
		$title = "详细信息";
		include $this->template('messagedetail');

	}


	//会员中心我的鉴宝
	public function doMobilemyjianbao(){
		global $_W, $_GPC;
		$openid = $_W['openid'];
        $login = trylogin($openid);
        if(is_array($login)){
            $user = trylogin($openid);
        }else{
            $user = 0;
        }
        if($_GPC['mark'])
        {
        	$user['mark']==$_GPC['mark'];
        }
        if($user){
            $this->assign('user',$user);
            if($user['mark']==1)
            {
				$totalfans = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('shopping_goods_collect')." where openid='".$_W['openid']."' ");
				$expertinfo = pdo_fetch("select id from " .tablename('shopping_goods'). " where openid='".$_W['openid']."'");
				$expertid = $expertinfo['id'];
				//var_dump($expertid);
				$jiandingnum = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('shopping_order')." where zjopenid='".$_W['openid']."' and status>=2 ");
				//var_dump($jiandingnum);

            }
            //待鉴定未读数

            
            if($user['mark']==0)
            {
            	//会员待鉴定未读消息
            	$djianding = pdo_fetch("select id from " .tablename('shopping_order')." where from_user='".$_W['openid']."' and status=1");
            	if(!empty($djianding['id']))
            	{
            		$wdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where from_user='".$_W['openid']."' and status=1");
            	}
            	//会员已鉴定未读数
            	$zjjianding = pdo_fetch("select id from " .tablename('shopping_order')." where from_user='".$_W['openid']."' and status>=2");
            	if(!empty($zjjianding['id']))
            	{
            		$yjdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where from_user='".$_W['openid']."' and status>=2 and yjd= '0' ");
            	}
            	//会员无法鉴定未读数
            	$zjwfjd = pdo_fetch("select id from " .tablename('shopping_order')." where from_user='".$_W['openid']."' and status=-1");
            	if(!empty($zjwfjd['id']))
            	{
            		$wfjdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where from_user='".$_W['openid']."' and status=-1 and wfjd= '0' ");
            	}

            	//会员我的证书小点和数字
            	$mcerttotal = pdo_fetchcolumn("select count(*) from " .tablename('shopping_certificate'). " where openid='".$_W['openid']."' and status>=1 and status<3");
            }
        	else
        	{
        		//专家待鉴定个数
        		$djianding = pdo_fetch("select id from " .tablename('shopping_order')." where zjopenid='".$_W['openid']."' and (status=1 or reson=1)");
            	if(!empty($djianding['id']))
            	{
            		
            		$wdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where zjopenid='".$_W['openid']."' and (status=1 or reson=1)");
            	}
            	//专家已鉴定未读消息
        		$zjjianding = pdo_fetch("select id from " .tablename('shopping_order')." where zjopenid='".$_W['openid']."'  and (status>=2 or reson=2)");
            	if(!empty($zjjianding['id']))
            	{
            		
            		$yjdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_order')." where zjopenid='".$_W['openid']."' and zjyjd=0 and (status>=2 or reson=2)");
            	}

            	//专家我的证书小点和数字
            	$zcerttotal = pdo_fetchcolumn("select count(*) from " .tablename('shopping_certificate'). " where zjopenid='".$_W['openid']."' and status>=1 and status<3");


        	}
        	//鉴宝待支付总数 cqn
			$jbdzf = pdo_fetchcolumn("select count(*) from " .tablename('shopping_order')."where status=0 and from_user='".$_W['openid']."'");
			//证书待支付总数 cqn
			$zsdzf = pdo_fetchcolumn("select count(*) from " .tablename('shopping_certificate')."where status=0 and openid='".$_W['openid']."'");
            $dzftotal = $jbdzf + $zsdzf;
            $title = "我的鉴宝";


            include $this->template('myjianbao',array('mark'=>$user['mark']));
        }else{
            include $this->template('register');
        }
	}

	//会员中心申请证书 cqn
	public function doMobilezsagreement(){
		global $_GPC,$_W;
		$cfg = $this->module['config'];
		$title = "我的证书";
		include $this->template('zhengshuxieyi');
		
	}
	//个人中心新增我的地址 2016/80/31 cqn
	public function doMobileaddaddress(){
		global $_GPC,$_W;
		$op = 0;
		//新增我的地址
		if($_GPC['act']=="add")
		{
			$datas = array(
							 'openid' => $_W['openid'],
							 'mobile' => $_GPC['mobile'],
							 'username' => $_GPC['name'],
							 'province' => $_GPC['provice'],
							 'city' => $_GPC['city'],
							 'district' => $_GPC['s_county'],
							 'address' => $_GPC['xiangxi'],
						  );
			$info = pdo_insert('mc_member_address', $datas);
			if($info)
			{
				die(json_encode(array('status'=>1)));
			}
			else
		    {
		    	die(json_encode(array('status'=>0)));
		    }
			
		}
		if($_GPC['id'])
		{

			$address = pdo_fetch("select * from " .tablename("mc_member_address")."where id=".$_GPC['id']);
			$op = 1;
		}
		//修改我的地址
		if($_GPC['act']=='edit')
		{
			$id = $_GPC['id'];
			$address = pdo_fetch("select * from".tablename('mc_member_address')."where id=".$id);
			$edit = pdo_update(
					'mc_member_address',
					array(
						'username' => $_GPC['name'],
						'mobile'   => $_GPC['mobile'],
						'province'   => $_GPC['provice'],
						'city'   => $_GPC['city'],
						'district'   => $_GPC['s_county'],
						'address'  => $_GPC['xiangxi']
					),
					array('id' => $id)
				);

				die(json_encode(array('status'=>1,'edit'=>$edit)));

			
		}
		include $this->template('addadress');

	}

	//个人中心三级联动 cqn
	public function doMobilesjld(){
        global $_GPC,$_W;
        if($_W['ispost']){
        $edit = pdo_update(
					'mc_member_address',
					array(
						'province'   => $_GPC['province'],
						'city'   => $_GPC['city'],
						'district'   => $_GPC['s_county']
					),
					array('id' => $_GPC['id'])
				);

				die(json_encode(array('status'=>1)));
			}

		include $this->template('sjld');

	}
	//个人中心管理我的地址 cqn
	public function doMobileeditaddress(){
		global $_GPC,$_W;
		$pindex = max(1, intval($_GPC["page"]));
		//var_dump($_GPC['page']);
		$psize = 8;
		$status = 1;
		$sql = "select * from".tablename('mc_member_address')."where openid='".$_W['openid']."' LIMIT ".($pindex - 1) * $psize . ',' . $psize;
		$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_member_address') . " WHERE     openid='".$_W['openid']."' ");
		$adress = pdo_fetchall($sql, $params);
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){

			if($_GPC['act']=='del')
			{
				$adress = pdo_delete('mc_member_address', array('id' => $_GPC['id']));
				if($adress)
				{
					die(json_encode(array('status'=>1)));
				}
				else
		    	{
		    		die(json_encode(array('status'=>0)));
		    	}
			}

			return json_encode($adress);
			exit;
		}

		//var_dump($adress);
		$this->assign('adress',$adress);
		include $this->template('editadress');
	}





	//证书提交申请以及支付页面 2016/80/09 cqn
	public function doMobilezszf(){
		global $_GPC, $_W;
		$act = trim($_GPC['act']);
		$feiyong = pdo_fetch("select feiyong from " .tablename('uni_settings'));
		$fei= $feiyong['feiyong'];
		//我的地址
		$addressinfo = pdo_fetchall("select * from ".tablename('mc_member_address')." where openid='".$_W['openid']."' ");
		//var_dump($_GPC);
		//选择我的地址
		if(!empty($_GPC['dzid']))
		{
			$addinfo = pdo_fetchall("select * from ".tablename('mc_member_address')." where openid='".$_W['openid']."' and id=".$_GPC['dzid']);
			//var_dump($addinfo);
		}
		else{
			$addinfo = pdo_fetchall("select * from ".tablename('mc_member_address')." where openid='".$_W['openid']."'");
			if($addinfo[0]['id'])
			{
				$addinfo = pdo_fetchall("select * from ".tablename('mc_member_address')." where openid='".$_W['openid']."' order by id desc limit 1");
			}
		}
		if($act == 'weixinpay')
		{
			$order = pdo_fetch("select * from " .tablename('shopping_certificate')." where orderid='".$_GPC['orderid']."'");
			$orderinfo = pdo_fetch("select zjopenid,status from " .tablename('shopping_order')." where id='".$_GPC['orderid']."' ");
			if(empty($order['orderid']))
			{
				if(!empty($_GPC['name']) && !empty($_GPC['mobile']) && !empty($_GPC['price']) && !empty($_GPC['provice']) && !empty($_GPC['city']))
				{
					$ordersn = date('Ymd') . random(4, 1);
					$datas = array(
							'orderid' => $_GPC['orderid'],
							'ordersn' => $ordersn,
							'name' => $_GPC['name'],
							'mobile' => $_GPC['mobile'],
							'price'  => $_GPC['price'],
							'provice' => $_GPC['provice'],
							'city' => $_GPC['city'],
							'district' => $_GPC['s_county'],
							'xiangxi' => $_GPC['xiangxi'],
							'status' => 0,
							'createtime' => TIMESTAMP,
							'zjopenid'   => $orderinfo['zjopenid'],
							'openid' => $_W['openid'],
							);
					pdo_insert('shopping_certificate', $datas);
					$addinfo = pdo_fetchall("select * from ".tablename('mc_member_address')." where openid='".$_W['openid']."'");
					if(empty($addinfo[0]['id']))
					{
						$datadz = array(
									'username' => $_GPC['name'],
									'mobile' => $_GPC['mobile'],
									'province' => $_GPC['provice'],
									'city' => $_GPC['city'],
									'district' => $_GPC['s_county'],
									'address' => $_GPC['xiangxi'],
									'openid' => $_W['openid'],
									);
						pdo_insert('mc_member_address', $datadz);
					}
						$data = array();
						$wOpt = $this->getowpt($_GPC['price'],'申请证书');
						$data['status'] = 1;
						$data['role'] = 'fans';
						$data['appId'] = $wOpt['appId'];
						$data['uniontid'] = $wOpt['uniontid'];
						$data['timeStamp'] = $wOpt['timeStamp'];
						$data['nonceStr'] = $wOpt['nonceStr'];
						$data['package'] = $wOpt['package'];
						$data['signType'] = $wOpt['signType'];
						$data['paySign'] = $wOpt['paySign'];
						$data['ordersn'] = $ordersn;
						$data['orderid'] = $_GPC['orderid'];
						pdo_update("shopping_certificate", array('uniontid'=>$wOpt['uniontid']), array("orderid" => $_GPC['orderid']));
						die(json_encode($data));
				}

			}
			else
			{
				if($_GPC['name']!=$order['name'] || $_GPC['mobile']!=$order['mobile']|| $_GPC['provice']!=$order['provice'] || $_GPC['city']!=$order['city'] || $_GPC['s_county']!=$order['district'] || $_GPC['xiangxi']!=$order['xiangxi'])
				{
					$data['name'] = $_GPC['name']; 
					$data['mobile'] = $_GPC['mobile'];
					$data['provice'] = $_GPC['provice'];
					$data['city'] = $_GPC['city'];
					$data['district'] = $_GPC['s_county'];
					$data['xiangxi'] = $_GPC['xiangxi'];
					pdo_update("shopping_certificate", $data, array("orderid" => $_GPC['orderid']));
				}
				if($order['status']==1 || $order['status']==2 || $order['status']==-1)
				{
					die(json_encode(array("status" => 0)));
				}
				else
				{
					$data = array();
					$wOpt = $this->getowpt($_GPC['price'],'申请证书');
					$data['status'] = 1;
					$data['role'] = 'fans';
					$data['appId'] = $wOpt['appId'];
					$data['uniontid'] = $wOpt['uniontid'];
					$data['timeStamp'] = $wOpt['timeStamp'];
					$data['nonceStr'] = $wOpt['nonceStr'];
					$data['package'] = $wOpt['package'];
					$data['signType'] = $wOpt['signType'];
					$data['paySign'] = $wOpt['paySign'];
					$data['ordersn'] = $ordersn;
					$data['orderid'] = $_GPC['orderid'];
					pdo_update("shopping_certificate", array('uniontid'=>$wOpt['uniontid']), array("orderid" => $_GPC['orderid']));
					die(json_encode($data));
				}
			}
			
		}
		if($act == 'post_success'){
			$orderid = $_GPC['orderid'];
			$datastatus['status'] = 1; 
			$datastatus['paytime'] = time();
			pdo_update("shopping_certificate", $datastatus, array("orderid" => $orderid));
			pdo_update("shopping_order",array('zspay'=>1),array('id'=>$orderid));
                //申请证书给专家发短信
            $expert = pdo_fetch("select * from ".tablename("shopping_order")." where id = '".$orderid."'");
            $expertopenid = $expert['zjopenid'];
            $expertinfo = pdo_fetch("select phone from ".tablename("shopping_goods")." where openid = '".$expertopenid."'");
            $expertphone = $expertinfo['phone'];
            


            sendtext($expertphone,6,0,substr($expert['uniontid'],8,15));
            //申请证书给客服发模板消息
            $sendinfo= pdo_fetch("select * from".tablename('shopping_sendwechatsetting'));
            $openid = $sendinfo['seropenid'];
            $data= $sendinfo['remark5'];
            send_templete_messages($openid,6,$data,$_W['siteroot'],$orderid);
            //申请证书给专家发模板消息
            send_templete_messages($expertopenid,6,$data,$_W['siteroot']."app/".$this->createMobileUrl('zjcertificate',array('openid' => $expertopenid)),$orderid);
			$datares = array();
			$datares['ispay'] = 1;
			die(json_encode($datares));
		}
		$title = "证书支付";
		include $this->template('zszf');
	}






	//我的证书 2016/8/11 cqn
	public function doMobilecertificate(){
		global $_GPC,$_W;
		$openid = $_GPC['openid'];
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 6;
		//查询我的订单
		$goods = pdo_fetchall("SELECT o.*, c.wuliu,c.status,c.orderid,c.uniontid  FROM " . tablename('shopping_order') .
					" o left join " . tablename('shopping_certificate') . "c on o.id=c.orderid " . " WHERE c.openid='{$openid}' and c.status >= '1' LIMIT ".($pindex - 1) * $psize . ',' . $psize);
		$total = pdo_fetchcolumn("SELECT count(*)  FROM " . tablename('shopping_order') .
					" o left join " . tablename('shopping_certificate') . "c on o.id=c.orderid " . " WHERE c.openid='{$openid}' and c.status >= '1' LIMIT ".($pindex - 1) * $psize . ',' . $psize);
		foreach ($goods as $key => $val) {
			$goods[$key]['upimgs']= unserialize($val['upimg'])[0];
			$goods[$key]['url'] = $this->createMobileUrl('case', array('id' => $val['orderid']));
			$goods[$key]['urlcon'] = $this->createMobileUrl('certificate', array('op'=>'confirm','id' => $val['orderid'],'zhengshu'=>1));
            $goods[$key]['context'] = mb_substr($val['context'],0,50,'utf-8');
            if((strlen($val['context'])/3) > 50){
                $goods[$key]['context'] .= "...";
            } 
		}
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){
			return json_encode($goods);
			exit;
		}
		$this->assign('goods',$goods);
		if($_GPC['op']=='confirm')
		{
			$cerinfo = pdo_update("shopping_certificate",array('status'=>3),array('orderid'=>$_GPC['orderid']));
			$cerinfo = pdo_update("shopping_order",array('status'=>3,'zspay'=>3),array('id'=>$_GPC['orderid']));
			if(isset($cerinfo))
			{
				message('确认收货成功', $this->createMobileUrl('certificate',array('openid'=>$_W['openid'])), 'success');
			}

		}
		//var_dump($goods);
		//未读我的证书
		$wdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_certificate')." where openid='".$_W['openid']."' and yidu= '0' ");
		$title = "我的证书";
		include $this->template('certificate');
	}


	//会员中心我的收藏 2016/8/12 cqn
	public function doMobilemycollect(){
		global $_GPC,$_W;
		$openid = $_W['openid'];
		//var_dump($openid);
		$operation = !empty($_GET['op']) ? $_GET['op'] : 'display';
		//var_dump($operation);
		if($operation=='display')
		{
			$title = "我的收藏";
			include $this->template('mycollect');
		}
		if($_GPC['op']=='myluyin')
		{
			$pindex = max(1, intval($_GPC["page"]));
			//var_dump($_GPC['page']);
			$psize = 5;
			$status = 1;
			$class = pdo_fetchall("SELECT g.*, c.*  FROM " . tablename('shopping_class') .
					" g left join " . tablename('shopping_class_collect') . "c on g.id=c.classid " . " WHERE c.openid='".$_W['openid']."'  LIMIT ".($pindex - 1) * $psize . ',' . $psize);
			 
			$total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('shopping_class') .
					" g left join " . tablename('shopping_class_collect') . "c on g.id=c.classid " . " WHERE c.openid='".$_W['openid']."'");
			//var_dump($total);
			foreach($class as $key=>$val){

				$expert = pdo_fetch("select openid from ".tablename('shopping_class')."where id='".$val['classid']."'");
				$class[$key]['openid'] = $expert['openid'];
				$expert = pdo_fetch("select avatar from ".tablename('shopping_goods')."where openid='".$expert['openid']."'");
				$class[$key]['avatar'] = $expert['avatar'];
				$class[$key]['newthumb'] =tomedia($val['thumb']);
				$class[$key]['catename'] = pdo_getcolumn('shopping_category', array('id' => $val['pcate']), 'name');
				$class[$key]['mobileurl'] = $this->createMobileUrl('yiclassdetail', array('id' => $val['id'],'sc'=>1));
			}
			//var_dump($class);
			//var_dump($total);
			$pager = pagination($total, $pindex, $psize);
			if($_W['ispost']){
				return json_encode($class);
				exit;
			}
			//var_dump($class);
			$this->assign('class',$class);
			$title = "我收藏的语音课堂";
			include $this->template('myluyin');
		}
		elseif($_GPC['op']=='myexpert')
		{
			$pindex = max(1, intval($_GPC["page"]));
			//var_dump($_GPC['page']);
			$psize = 7;
			$status = 1;
			$goods = pdo_fetchall("SELECT g.*, c.*  FROM " . tablename('shopping_goods') .
					" g left join " . tablename('shopping_goods_collect') . "c on g.id=c.goodid " . " WHERE c.openid='".$_W['openid']."'  LIMIT ".($pindex - 1) * $psize . ',' . $psize);
			 
			$total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('shopping_goods') .
					" g left join " . tablename('shopping_goods_collect') . "c on g.id=c.goodid " . " WHERE c.openid='".$_W['openid']."'");
			//var_dump($total);
			foreach($goods as $key=>$val){
				$goods[$key]['newthumb'] =tomedia($val['thumb']);
				$goods[$key]['catename'] = pdo_getcolumn('shopping_category', array('id' => $val['pcate']), 'name');
				$goods[$key]['mobileurl'] = $this->createMobileUrl('jianbaoxiyi', array('id' => $val['goodid']));
				$goods[$key]['zjurl'] = $this->createMobileUrl('zhuanjiadetail', array('id' => $val['goodid'],'mine'=>1));
			}
			//var_dump($goods);
			$pager = pagination($total, $pindex, $psize);
			if($_W['ispost']){
				return json_encode($goods);
				exit;
			}
			$this->assign('goods',$goods);
			//var_dump($goods);
			$title = "我收藏的专家";
			include $this->template('myexpert');
		}
		elseif($_GPC['op']=='mygoods')
		{
			$title = "我的收藏";
			include $this->template('mygoods');
		}
		


	}

	//专家的证书 2016/8/11 cqn
	public function doMobilezjcertificate(){
		global $_GPC,$_W;
		$openid = $_W['openid'];
		$pindex = max(1, intval($_GPC["page"]));
		$psize = 6;
		//查询我的订单
		if(empty($_GPC['zspay'])||$_GPC['zspay']==0){
			$goods = pdo_fetchall("SELECT o.*, c.wuliu,c.status as certstatus,c.orderid,c.uniontid as certuniontid  FROM " . tablename('shopping_order') .
					" o left join " . tablename('shopping_certificate') . "c on o.id=c.orderid " . " WHERE c.zjopenid='{$openid}' and c.status=1 order by c.id desc LIMIT ".($pindex - 1) * $psize . ',' . $psize);
			$total = pdo_fetchcolumn("SELECT count(*)  FROM " . tablename('shopping_order') .
					" o left join " . tablename('shopping_certificate') . "c on o.id=c.orderid " . " WHERE c.openid='{$openid}'  and c.status=1 LIMIT ".($pindex - 1) * $psize . ',' . $psize);
		}
		else
		{
			$goods = pdo_fetchall("SELECT o.*, c.wuliu,c.status as certstatus,c.orderid,c.uniontid as certuniontid  FROM " . tablename('shopping_order') .
					" o left join " . tablename('shopping_certificate') . "c on o.id=c.orderid " . " WHERE c.zjopenid='{$openid}' and c.status>=2 order by c.id desc LIMIT ".($pindex - 1) * $psize . ',' . $psize);
			$total = pdo_fetchcolumn("SELECT count(*)  FROM " . tablename('shopping_order') .
					" o left join " . tablename('shopping_certificate') . "c on o.id=c.orderid " . " WHERE c.openid='{$openid}'  and c.status>=2 LIMIT ".($pindex - 1) * $psize . ',' . $psize);
		}
		
		foreach ($goods as $key => $val) {
			$goods[$key]['upimgs']= unserialize($val['upimg'])[0];
			$goods[$key]['url'] = $this->createMobileUrl('case', array('id' => $val['orderid'],'zjzhengshu'=>1));
			$goods[$key]['urlcon'] = $this->createMobileUrl('certificate', array('op'=>'confirm','id' => $val['orderid']));
            $goods[$key]['context'] = mb_substr($val['context'],0,50,'utf-8');
            $goods[$key]['jbuniontid'] = $val['uniontid'];
            $goods[$key]['certuniontid'] = $val['certuniontid'];
            if((strlen($val['context'])/3) > 50){
                $goods[$key]['context'] .= "...";
            } 
		}
		//var_dump($goods);
		$pager = pagination($total, $pindex, $psize);
		if($_W['ispost']){
			return json_encode($goods);
			exit;
		}

		//var_dump($orderinfo[0]['certuniontid']);
		//未读我的证书
		$wdtotal = pdo_fetchcolumn("select count(*) from ".tablename('shopping_certificate')." where openid='".$_W['openid']."' and yidu= '0' ");
		//var_dump($orderinfo);
		$title = "我的证书";
		include $this->template('zjcertificate');
	}

	//专家鉴定须知 cqn 2016/08/11
	public function doMobilejiandingxz(){
		include $this->template('jiandingxz');
	}
		





	//会员评价鉴宝  2016/08/09 cqn
	public function doMobilecomment(){
		global $_GPC,$_W;
		//var_dump($_GPC);
		$openid = $_W['openid'];
		$orderid = $_GPC['orderid'];
		$expertid = $_GPC['expert'];
        $userinfo = pdo_fetch("select * from ".tablename('mc_members'). "where openid='".$openid."'");
        $expertinfo = pdo_fetch("select * from ".tablename('shopping_goods'). "where id='".$expertid."'");
        //var_dump($userinfo);
        //var_dump($expertinfo);
	
        if($_GPC['op']=='submit')
        {
        	//判断用户是否已提价过评论
        	$commentinfo = pdo_fetch("select id from" .tablename('shopping_comment'). " where memberid=".$userinfo['uid']. " and expertid= '".$_GPC['expertid']."' and orderid='".$_GPC['orderid']."' ");
			if(!empty($commentinfo['id']))
			{
				message('您已经评论过了！', $this->createMobileUrl('myorder', array('status' => '2')), 'error');
			}
        	//三星已下不显示，三星以上显示
        	if($_GPC['score']<=3)
        	{
        		$show = 0;
        	}
        	else
        	{
        		$show = 1;
        	}
        	$data = array(
				'orderid'   => $_GPC['orderid'],         //classname在前台显示的值是名字，value值是class_id
				'star'      => $_GPC['score'],
				'content'     => $_GPC['content'],
				'memberid'    => $userinfo['uid'],
				'expertid'      => $_GPC['expertid'],
				'created_at' => TIMESTAMP,
				'nickname'   => $userinfo['nickname'],
				'status'     => 1,
				'phone'      => $userinfo['mobile'],
				'shows'       => $show
			);
			$comment = pdo_insert('shopping_comment', $data);
			if(isset($comment))
			{
				pdo_update(
					'shopping_order',
					array(
						'iscomment' => 1
					),
					array('id' => $_GPC['orderid'])
				);
				message('您的评价已提交，后台审核通过后可在前台显示', $this->createMobileUrl('myorder', array('status' => '2')), 'success');
			}
		}
			$title = "评价";
			include $this->template('comment');
		}


	//会员申请退款 2016/08/10 cqn
	public function doMobilerefund(){
		global $_GPC,$_W;
		if(!empty($_GPC['orderid']))
		{
			$refund = pdo_update(
					'shopping_order',
					array(
						'refund' => 1
					),
					array('id' => $_GPC['orderid'])
				);
			if(isset($refund))
			{
				//会员申请退款给客服发短信
				$expert = pdo_fetch("select * from ".tablename("shopping_order")." where id = '".$_GPC['orderid']."'");
	            //重要给客服发短信
	            $uniontid = substr($expert['uniontid'],8,15);
				sendtext(0,7,0,$uniontid);
				//会员申请退款给客服发模板消息
				$sendinfo= pdo_fetch("select * from".tablename('shopping_sendwechatsetting'));
				$openid = $sendinfo['seropenid'];
				$data= $sendinfo['remark6'];
				$this->send_templete_message($openid,7,$data,$_W['siteroot'],$_GPC['orderid']);
				message('退款申请已提交，我们会在3天内进行受理', $this->createMobileUrl('myorder', array('status' => '1')), 'success');
				
			}

		}
	}
    


	//后台证书管理 cqn
	public function doWebcertificate(){
		global $_GPC,$_W;
		load()->func('tpl');
		$operation = !empty($_GET['op']) ? $_GET['op'] : 'display';

		if ($operation == 'display') {
			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$status = $_GET['status'];
			$sendtype = !isset($_GPC['sendtype']) ? 0 : $_GPC['sendtype'];
			$condition = " 1= 1";
			$paras = array(':weid' => $_W['uniacid']);

			/*if (empty($starttime) || empty($endtime)) {
				$starttime = strtotime('-1 month');
				$endtime = TIMESTAMP;
			}
			if (!empty($_GPC['time'])) {
				$starttime = strtotime($_GPC['time']['start']);
				$endtime = strtotime($_GPC['time']['end']) + 86399;
				$condition .= " AND o.createtime >= :starttime AND o.createtime <= :endtime ";
				$paras[':starttime'] = $starttime;
				$paras[':endtime'] = $endtime;
			}*/
			if (!empty($_GPC['paytype'])) {
				$condition .= " AND o.paytype = '{$_GPC['paytype']}'";
			} elseif ($_GPC['paytype'] === '0') {
				$condition .= " AND o.paytype = '{$_GPC['paytype']}'";
			}
			if (!empty($_GPC['keyword'])) {
				$condition .= " AND o.ordersn LIKE '%{$_GPC['keyword']}%'";
			}
			if (!empty($_GPC['member'])) {
				$condition .= " AND o.mobile LIKE '%{$_GPC['member']}%'";
			}
			if ($status != '') {
				$condition .= " AND o.status = '" . intval($status) . "'";
			}
			if (!empty($sendtype)) {
				$condition .= " AND o.sendtype = '" . intval($sendtype) . "' AND status != '3'";
			}
			$sql = 'SELECT COUNT(*) FROM ' . tablename('shopping_certificate') . ' AS `o` WHERE ' . $condition;
			$total = pdo_fetchcolumn($sql, $paras);
			if ($total > 0) {

				if ($_GPC['export'] != 'export') {
					$limit = ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				}

				$sql = 'SELECT * FROM ' . tablename('shopping_certificate') . ' AS `o` WHERE ' . $condition . ' ORDER BY
						`o`.`createtime` DESC, `o`.`createtime` DESC ' . $limit;
				$list = pdo_fetchall($sql,$paras);
				$pager = pagination($total, $pindex, $psize);
				$paytype = array (
					'0' => array('css' => 'default', 'name' => '未支付'),
					'1' => array('css' => 'danger','name' => '余额支付'),
					'2' => array('css' => 'info', 'name' => '在线支付'),
					'3' => array('css' => 'warning', 'name' => '货到付款'),
					'4' => array('css' => 'info', 'name' => '无需支付')
				);
				$orderstatus = array (
					'-1' => array('css' => 'default', 'name' => '已取消'),
					'0' => array('css' => 'danger', 'name' => '待付款'),
					'1' => array('css' => 'info', 'name' => '待发货'),
					'2' => array('css' => 'warning', 'name' => '待收货'),
					'3' => array('css' => 'success', 'name' => '已完成')
				);

				foreach ($list as &$value) {
					$s = $value['status'];
					$value['statuscss'] = $orderstatus[$value['status']]['css'];
					$value['status'] = $orderstatus[$value['status']]['name'];
					$value['dispatch'] = pdo_fetchcolumn("SELECT `dispatchname` FROM " . tablename('shopping_dispatch') . " WHERE id = :id", array(':id' => $value['dispatch']));

					// 收货地址信息
					/*list($value['username'], $value['mobile'], $value['zipcode']) = explode('|', $value['address']);

					if ($s < 1) {
						$value['css'] = $paytype[$s]['css'];
						$value['paytype'] = $paytype[$s]['name'];
						continue;
					}*/
					$value['css'] = $paytype[$value['paytype']]['css'];
					if ($value['paytype'] == 2) {
						if (empty($value['transid'])) {
							$value['paytype'] = '支付宝支付';
						} else {
							$value['paytype'] = '微信支付';
						}
					} else {
						$value['paytype'] = $paytype[$value['paytype']]['name'];
					}
				}
				if ($_GPC['export'] != '') {
					/* 输入到CSV文件 */
					$html = "\xEF\xBB\xBF";

					/* 输出表头 */
					$filter = array(
						'ordersn' => '订单号',
						'goods_title' => '商品',
						'username' => '姓名',
						'mobile' => '电话',
						'paytype' => '支付方式',
						'dispatch' => '配送方式',
						'dispatchprice' => '运费',
						'price' => '总价',
						'status' => '状态',
						'createtime' => '下单时间',
						'zipcode' => '邮政编码',
						'address' => '收货地址信息'
					);

					foreach ($filter as $key => $title) {
						$html .= $title . "\t,";
					}
					$html .= "\n";
					foreach ($list as $k => $v) {
						foreach ($filter as $key => $title) {
							$good = pdo_get('shopping_order_goods', array('orderid' => $v['id']));
							$good = pdo_get('shopping_goods', array('id' => $good['goodsid']));
							$v['goods_title'] = $good['title'];
							if ($key == 'createtime') {
								$html .= date('Y-m-d H:i:s', $v[$key]) . "\t, ";
							} else {
								$html .= $v[$key] . "\t, ";
							}
						}
						$html .= "\n";
					}
					/* 输出CSV文件 */
					header("Content-type:text/csv");
					header("Content-Disposition:attachment; filename=全部数据.csv");
					echo $html;
					exit();

				}

			}
		} elseif ($operation == 'detail') {
			$id = intval($_GPC['id']);
			$item = pdo_fetch("SELECT * FROM " . tablename('shopping_certificate') . " WHERE id = :id ", array(':id' => $id));
			if (empty($item)) {
				message("抱歉，订单不存在!", referer(), "error");
			}
			if (checksubmit('confirmsend')) {
				if (!empty($_GPC['isexpress']) && empty($_GPC['expresssn'])) {
					message('请输入快递单号！');
				}
				$item = pdo_fetch("SELECT transid FROM " . tablename('shopping_certificate') . " WHERE id = :id", array(':id' => $id));
				if (!empty($item['transid'])) {
					$this->changeWechatSend($id, 1);
				}
				pdo_update(
					'shopping_certificate',
					array(
						'status' => 2,
						'remark' => $_GPC['remark'],
						'express' => $_GPC['express'],
						'expresscom' => $_GPC['expresscom'],
						'expresssn' => $_GPC['expresssn'],
					),
					array('id' => $id)
				);
				message('发货操作成功！', referer(), 'success');
			}
			/*if (checksubmit('cancelsend')) {
				$item = pdo_fetch("SELECT transid FROM " . tablename('shopping_order') . " WHERE id = :id AND weid = :weid", array(':id' => $id, ':weid' => $_W['uniacid']));
				if (!empty($item['transid'])) {
					$this->changeWechatSend($id, 0, $_GPC['cancelreson']);
				}
				pdo_update(
					'shopping_order',
					array(
						'status' => 1,
						'remark' => $_GPC['remark'],
					),
					array('id' => $id)
				);
				message('取消发货操作成功！', referer(), 'success');
			}*/
			if (checksubmit('finish')) {
				pdo_update('shopping_certificate', array('status' => 3, 'remark' => $_GPC['remark']), array('id' => $id));
				message('订单操作成功！', referer(), 'success');
			}
			if (checksubmit('cancel')) {
				pdo_update('shopping_certificate', array('status' => 1, 'remark' => $_GPC['remark']), array('id' => $id));
				message('取消完成订单操作成功！', referer(), 'success');
			}
			if (checksubmit('cancelpay')) {
				pdo_update('shopping_certificate', array('status' => 0, 'remark' => $_GPC['remark']), array('id' => $id));
				//设置库存
				$this->setOrderStock($id, false);
				//减少积分
				$this->setOrderCredit($id, false);

				message('取消订单付款操作成功！', referer(), 'success');
			}
			if (checksubmit('confrimpay')) {
				pdo_update('shopping_certificate', array('status' => 1, 'paytype' => 2, 'remark' => $_GPC['remark']), array('id' => $id));
				//设置库存
				$this->setOrderStock($id);
				//增加积分
				$this->setOrderCredit($id);
				message('确认订单付款操作成功！', referer(), 'success');
			}
			/*if (checksubmit('close')) {
				$item = pdo_fetch("SELECT transid FROM " . tablename('shopping_order') . " WHERE id = :id AND weid = :weid", array(':id' => $id, ':weid' => $_W['uniacid']));
				if (!empty($item['transid'])) {
					$this->changeWechatSend($id, 0, $_GPC['reson']);
				}
				pdo_update('shopping_order', array('status' => -1, 'remark' => $_GPC['remark']), array('id' => $id, 'weid' => $_W['uniacid']));
				message('订单关闭操作成功！', referer(), 'success');
			}*/
			/*if (checksubmit('open')) {
				pdo_update('shopping_order', array('status' => 0, 'remark' => $_GPC['remark']), array('id' => $id, 'weid' => $_W['uniacid']));
				message('开启订单操作成功！', referer(), 'success');
			}*/
			// 订单取消
			if (checksubmit('cancelorder')) {
				if ($item['status'] == 1) {
					load()->model('mc');
					$memberId = mc_openid2uid($item['from_user']);
					mc_credit_update($memberId, 'credit2', $item['price'], array($_W['uid'], '微商城取消订单退款说明'));
				}
				pdo_update('shopping_certificate', array('status' => '-1'), array('id' => $item['id']));
				message('订单取消操作成功！', referer(), 'success');
			}

			$dispatch = pdo_fetch("SELECT * FROM " . tablename('shopping_dispatch') . " WHERE id = :id", array(':id' => $item['dispatch']));
			if (!empty($dispatch) && !empty($dispatch['express'])) {
				$express = pdo_fetch("select * from " . tablename('shopping_express') . " WHERE id=:id limit 1", array(":id" => $dispatch['express']));
			}

			// 收货地址信息
			$item['user'] = explode('|', $item['address']);

			$goods = pdo_fetchall("SELECT g.*, o.total,g.type,o.optionname,o.optionid,o.price as orderprice FROM " . tablename('shopping_order_goods') .
					" o left join " . tablename('shopping_goods') . " g on o.goodsid=g.id " . " WHERE o.orderid='{$id}'");
			$item['goods'] = $goods;
		} elseif ($operation == 'delete') {
			/*订单删除*/
			$orderid = intval($_GPC['id']);
			if (pdo_delete('shopping_order', array('id' => $orderid))) {
				message('订单删除成功', $this->createWebUrl('order', array('op' => 'display')), 'success');
			} else {
				message('订单不存在或已被删除', $this->createWebUrl('order', array('op' => 'display')), 'error');
			}
		}elseif ($operation == 'wuliu')
		{

			
			if($_GET['id'])
			{
				$id = $_GET['id'];
				$wuliuinfo = pdo_fetch("select * from " .tablename('shopping_certificate'). " WHERE id = :id", array(':id' => $id));

			}
			if($_POST['wuliu'] && $_POST['id'])
			{
				$wuliu = $_POST['wuliu'];
				$id = $_POST['id'];
				$wuliuinfo = pdo_fetch("select * from " .tablename('shopping_certificate'). " WHERE id = :id", array(':id' => $id));
				pdo_update('shopping_certificate', array('wuliu' => $wuliu,'status' => 2), array('id' => $id));
				pdo_update('shopping_order', array('zspay' => 2), array('id' => $wuliuinfo['orderid']));
				message('添加成功', $this->createWebUrl('certificate', array('op' => 'display','status' => '2')), 'success');
			}
		}
		 //后台申请证书费用 cqn 2016/08/16 cqn
		elseif ($operation == 'feiyong')
		{
			$feiyong = pdo_fetch("select feiyong from " .tablename('uni_settings'));
			if($_POST['feiyong'])
			{
				$feiyong = $_POST['feiyong'];
				//var_dump($feiyong);

				pdo_update('uni_settings', array('feiyong' => $feiyong));
				message('修改成功', $this->createWebUrl('certificate', array('op' => 'feiyong')), 'success');
			}
		}

		include $this->template('certificate');
		
	}

























	//贡品分类板块wangtao

	public function doWebgongdengfenlei(){
		global $_GPC;
		$do = !empty($do) ? $do : 'display';
		$do = in_array($do, array('display', 'post', 'delete', 'fetch', 'check')) ? $do : 'display';
		//post方法为添加页的显示，和编辑页的显示
		if($_GET['act']=='post'){
			$do='post';
		}
		if($_GET['act']=='add'){
			$do='add';
		}
		if($_GET['act']=='delete'){
			$do='delete';
		}
		if($_GET['act']=='edit'){
			$do='edit';
		}
		//贡品类别列表
		if ($do == 'display') {
			$category = pdo_fetchall("SELECT * FROM ".tablename('gongdeng')." WHERE class_id ORDER BY class_id asc");
			include $this->template('gongdengfenlei');
		}
		//添加贡品分类到数据库
		elseif($do == 'add'){
			$classname = $_POST['classname'];
			$data = array( 
				'classname'   => $classname
			);
			pdo_insert('gongdeng', $data);
			message('保存成功',$this->createWebUrl('gongdengfenlei'),'success');

		}
		//删除贡品类别
		elseif($do == 'delete'){
			$class_id = $_GET['class_id'];
			$row = pdo_fetch("SELECT class_id FROM ".tablename('gongdeng')." WHERE class_id = ".$class_id);
			if (empty($row)) {
				message('抱歉，类别不存在或是已经被删除！');
			}
			$data = array(
				'class_id' => $class_id
			);
			pdo_delete('gongdeng', $data);
			message('删除成功',$this->createWebUrl('gongdengfenlei'),'success');

		}
		//添加或修改贡品类别
		elseif($do == 'post'){
			$class_id = $_GET['class_id'];
			if($class_id){ //更新贡品类别页
				$category = pdo_fetch("SELECT * FROM ".tablename('gongdeng')." WHERE class_id = ".$class_id);
				if(empty($category)) {
					message('分类不存在或已删除', '', 'error');
				}else{
					$classname = $_GET['classname'];
					$edit = 1;
					$this->assign('edit',$edit);
					$this->assign('class_id',$class_id);
					$this->assign('classname',$classname);
					include $this->template('gongdengfenlei');
				}
			}
			else{  //添加贡品类别页
				include $this->template('gongdengfenlei');
			}
		}
		elseif($do == 'edit') {
			$class_id = intval($_GET['class_id']);
			$classname = $_POST['classname'];
			$data = array(
				'classname' => $classname
			);
			$where = 'class_id ='.$class_id;
			pdo_update('gongdeng',$data,$where);
			message('更新分类成功！',$this->createWebUrl('gongdengfenlei'), 'success');
		}
		exit('error');
	}
	//贡品列表
	public function doWebgongdeng(){
		// uni_user_permission_check('imeepos_fvoice_news');
		//获取全部贡品
		//print_r($_GET['act']);die('aa');
		global $_GPC;
		$do = in_array($do, array('display', 'post', 'delete')) ? $do : 'display';
		if($_GET['act']=='post'){
			$do = 'post';
		}
		if($_GET['act']=='add'){
			$do = 'add';
		}
		if($_GET['act']=='delete'){
			$do = 'delete';
		}
		if($_GET['act']=='edit'){
			$do = 'edit';
		}
		$news = pdo_fetchall("SELECT * FROM ".tablename('member')." WHERE id ORDER BY id DESC");
		//贡品列表（默认）
		if($do == 'display') {
			$pindex = max(1, intval($_GPC['page']));
			$psize = 20;
			$params = array();
             $glist = pdo_fetchall("SELECT * FROM ".tablename('gongdeng'));
			//分页
            $cid = $_GET['cid'];
            $list = pdo_fetchall("SELECT * FROM ".tablename('member')." WHERE class_id = 1 ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize);

            if($cid == 1){
                $list = pdo_fetchall("SELECT * FROM ".tablename('member')." WHERE class_id = 1 ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize);
            }elseif($cid == 2){
                $list = pdo_fetchall("SELECT * FROM ".tablename('member')." WHERE class_id = 2 ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize);
            }elseif($cid == 3){
                $list = pdo_fetchall("SELECT * FROM ".tablename('member')." WHERE class_id = 3 ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize);
            }
			foreach($list as $key => $c){
				$classname=pdo_fetch("SELECT classname FROM ".tablename('gongdeng')." WHERE class_id = ".$c['class_id']);
				$list[$key]['classname'] = $classname['classname'];
			}
			$total = count($list);
			$pager = pagination($total, $pindex, $psize);
			include $this->template('gongdeng');
		}
		//添加贡品、系统消息的页
		if($do == 'post') {
            $msg = $_GET['msg'];
            if($msg){
                $id = $_GET['id'];
                if (!empty($id)) { //当前为编辑系统消息
                    $item = pdo_fetch("SELECT * FROM ".tablename('member')." WHERE id = :id" , array(':id' => $id));
                    $classfind = pdo_fetch("SELECT class_id,classname FROM ".tablename('gongdeng')." WHERE class_id = :class_id" ,
                        array(':class_id' => $item['class_id']));
                    $class = pdo_fetchall("SELECT * FROM ".tablename('gongdeng')." WHERE class_id ORDER BY class_id DESC");
                    if(empty($item)){
                        message('抱歉，文章不存在或是已经删除！');
                    }else{
                        $edit = 1;
                        $this->assign('edit',$edit);
                        $this->assign('id',$id);
                        $this->assign('classfind',$classfind);
                        $this->assign('item',$item);
                        $this->assign('class',$class);
                        include $this->template('msg');
                    }

                } else {//添加系统消息
                    $classfind = pdo_fetch("SELECT class_id,classname FROM ".tablename('gongdeng')." WHERE class_id = 3");
                    $getclass['class_id'] = $classfind['class_id'];
                    $getclass['classname'] = $classfind['classname'];
                    include $this->template('msg');
                }
            }else{
                $id = $_GET['id'];
                if (!empty($id)) { //当前为编辑贡品
                    $item = pdo_fetch("SELECT * FROM ".tablename('member')." WHERE id = :id" , array(':id' => $id));
                    $classfind = pdo_fetch("SELECT class_id,classname FROM ".tablename('gongdeng')." WHERE class_id = :class_id" ,
                        array(':class_id' => $item['class_id']));
                    $class = pdo_fetchall("SELECT * FROM ".tablename('gongdeng')." WHERE class_id ORDER BY class_id DESC");
                    if(empty($item)){
                        message('抱歉，文章不存在或是已经删除！');
                    }else{
                        $edit = 1;
                        $this->assign('edit',$edit);
                        $this->assign('id',$id);
                        $this->assign('classfind',$classfind);
                        $this->assign('item',$item);
                        $this->assign('class',$class);
                        include $this->template('gongdeng');
                    }

                } else {
                    $getclass['class_id'] = $_GET['class_id'];
                    $getclass['classname'] = $_GET['classname'];
                    $class = pdo_fetchall("SELECT * FROM ".tablename('gongdeng')." WHERE class_id ORDER BY class_id DESC");
                    $this->assign('class',$class);
                    $this->addign('getclass',$getclass);
                    include $this->template('gongdeng');
                }
            }
			
		}
		//添加贡品到数据库
		if($do == 'add'){
            $msg = $_GET['msg'];
            if($msg){
                if (empty($_GPC['title'])) {
                    message('标题不能为空，请输入标题！');
                }
                $classfind = pdo_fetch("SELECT class_id,classname FROM ".tablename('gongdeng')." WHERE class_id = 3");
                $data = array(
                    'class_id'   => $classfind['class_id'],         //classname在前台显示的值是名字，value值是class_id
                    'title'      => addslashes($_GPC['title']),
                    'prise'      => $_GPC['prise'],
                    'content'    => htmlspecialchars_decode($_GPC['content'], ENT_QUOTES),
                    'image'      => $_GPC['thumb'],
                    'createtime' => time()
                );
                pdo_insert('member', $data);
                message('保存成功',$this->createWebUrl('gongdeng'),'success');
            }else{
                if (empty($_GPC['title'])) {
                    message('标题不能为空，请输入标题！');
                }
                $data = array(
                    'class_id'   => intval($_GPC['classname']),         //classname在前台显示的值是名字，value值是class_id
                    'title'      => addslashes($_GPC['title']),
                    'prise'      => $_GPC['prise'],
                    'content'    => htmlspecialchars_decode($_GPC['content'], ENT_QUOTES),
                    'image'      => $_GPC['thumb'],
                    'createtime' => TIMESTAMP
                );
                pdo_insert('member', $data);
                message('保存成功',$this->createWebUrl('gongdeng'),'success');
            }
                

		}
		//编辑贡品
		if($do == 'edit'){
			$data = array(
				'class_id'   => intval($_GPC['classname']),         //classname在前台显示的值是名字，value值是class_id
				'title'      => addslashes($_GPC['title']),
				 'prise'      => $_GPC['prise'],
				'content'    => htmlspecialchars_decode($_GPC['content'], ENT_QUOTES),
				'image'      => $_GPC['thumb'],
				'createtime' => TIMESTAMP
			);
			$where = 'id = '.$_GET['id'];
			pdo_update('member', $data , $where);
			message('贡品更新成功！',$this->createWebUrl('gongdeng'),'success');

		}
		//删除贡品
		if($do == 'delete') {
			$id = intval($_GET['id']);
			$row = pdo_fetch("SELECT id FROM ".tablename('member')." WHERE id = ".$id);
			if (empty($row)) {
				message('抱歉，贡品不存在或是已经被删除！');
			}
			$data = array(
				'id' => $id
			);
			pdo_delete('member', $data);
			message('删除成功',$this->createWebUrl('gongdeng'),'success');

		}
	}















    
    //短信验证码设置板块
	public function doWebsendSMSsetting(){
        if($_GET['done']){
            $item = pdo_fetch("SELECT * FROM ".tablename('shopping_sendSMSsetting')." WHERE id = 1");
            $data = array(
                'zappkey'        => $_POST['zappkey'],
                'zappsecret'     => $_POST['zappsecret'],
                'zsignname'      => $_POST['zsignname'],
                'registertp'     => $_POST['registertp'],
                'doneregistertp' => $_POST['doneregistertp'],
                'resulttp'       => $_POST['resulttp'],
                'newordertp'     => $_POST['newordertp'],
                'expoutofdatetp' => $_POST['expoutofdatetp'],
                'seroutofdatetp' => $_POST['seroutofdatetp'],
                'certificatetp'  => $_POST['certificatetp'],
                'refundtp'       => $_POST['refundtp'],
                'overtimetp'     => $_POST['overtimetp'],
                'important'      => $_POST['important'],
                'phone'          => $_POST['phone']
            );
            if($item){
                $where = 'id = 1';
                pdo_update('shopping_sendSMSsetting', $data , $where);
                message('保存成功',$this->createWebUrl('sendSMSsetting'),'success');
            }else{
                pdo_insert('shopping_sendSMSsetting', $data);
                message('保存成功',$this->createWebUrl('sendSMSsetting'),'success');
            }
            
        }else{
            $show = pdo_fetch("SELECT * FROM ".tablename('shopping_sendSMSsetting')." WHERE id ");
            $this->assign('show',$show);
            include $this->template('sendSMSsetting');

        }
        
    }
    //微信通知设置板块 zsn 20160812    11:40
	public function doWebsendwechatsetting(){
        if($_GET['done']){
            $item = pdo_fetch("SELECT * FROM ".tablename('shopping_sendwechatsetting')." WHERE id = 1");
            $data = array(
                'seropenid'       => $_POST['seropenid'],
                'resulttp'       => $_POST['resulttp'],
                'newordertp'     => $_POST['newordertp'],
                'expoutofdatetp' => $_POST['expoutofdatetp'],
                'seroutofdatetp' => $_POST['seroutofdatetp'],
                'certificatetp'  => $_POST['certificatetp'],
                'refundtp'       => $_POST['refundtp'],
                'overtimetp'     => $_POST['overtimetp'],
                'important'      => $_POST['important'],
                'first1'          => $_POST['first1'],
                'first2'          => $_POST['first2'],
                'first3'          => $_POST['first3'],
                'first4'          => $_POST['first4'],
                'first5'          => $_POST['first5'],
                'first6'          => $_POST['first6'],
                'first7'          => $_POST['first7'],
                'first8'          => $_POST['first8'],
                'remark1'         => $_POST['remark1'],
                'remark2'         => $_POST['remark2'],
                'remark3'         => $_POST['remark3'],
                'remark4'         => $_POST['remark4'],
                'remark5'         => $_POST['remark5'],
                'remark6'         => $_POST['remark6'],
                'remark7'         => $_POST['remark7'],
                'remark8'         => $_POST['remark8']
            );
            if($item){
                $where = 'id = 1';
                pdo_update('shopping_sendwechatsetting', $data , $where);
                message('保存成功',$this->createWebUrl('sendwechatsetting'),'success');
            }else{
                pdo_insert('shopping_sendwechatsetting', $data);
                message('保存成功',$this->createWebUrl('sendwechatsetting'),'success');
            }
            
        }else{
            $show = pdo_fetch("SELECT * FROM ".tablename('shopping_sendwechatsetting')." WHERE id = 1");
            $this->assign('show',$show);
            include $this->template('sendwechatsetting');

        }
        
    }
    public function doMobiledotape(){
        global $_W,$_GPC;
		$act = trim($_GPC['act']);
        
        if($act == 'answer'){
			$serverId = trim($_GPC['serverId']);
			$timelong = intval($_GPC['timelong']);

			$data = array();
			$data['uniacid'] = $_W['uniacid'];
			$data['openid'] = $_W['openid'];
			$data['voice_id'] = $serverId;
			$data['isweixin'] = 1;
			$data['timelong'] = $timelong;
		//	$data['chart_id'] = $chart['id'];
			$data['create_time'] = time();

			pdo_insert('imeepos_fvoice_chart_log', $data);

			$data = array();
			$data['status'] = 1;
			$data['message'] = '发送成功';
			die(json_encode($data));
		}else{
            include $this->template('dotape');
        }
        
    }





























//deng wangtao
//web后台 
/* public function doWebgongdeng(){
     global $_GPC,$_W;
     $sql="SELECT * FROM".tablename('member');
     $list=pdo_fetchall($sql);
     include $this->template('gongdeng');
 }*/
//web前台
 public function doMobilegongdeng(){
     global $_GPC,$_W;
     $sql="SELECT * FROM".tablename('member');
     $list=pdo_fetchall($sql);
     include $this->template('gongdeng');
 }



/*
 public function doWebgongdengfenlei(){
     global $_GPC,$_W;
     $sql="SELECT * FROM".tablename('gongdeng');
     $list=pdo_fetchall($sql);
     include $this->template('gongdeng');
 }*/
//web前台
/*public function doMobilegongdengfenlei(){
     global $_GPC,$_W;
     $sql="SELECT * FROM".tablename('gongdeng');
     $list=pdo_fetchall($sql);
     include $this->template('gongdeng');
 }*/



  public function doWebgongdeng2(){
     global $_GPC,$_W;
      
     include $this->template('gongdeng2');
 }
  public function doMobilegongdeng2(){
     global $_GPC,$_W;
      
     include $this->template('gongdeng2');
 }



   public function doWebgongdeng3(){
     global $_GPC,$_W;
      
     include $this->template('gongdeng3');
 }
   public function doMobilegongdeng3(){
     global $_GPC,$_W;
      
     include $this->template('gongdeng3');
 }


     public function doWebgongdengge(){
     global $_GPC,$_W;
     
     include $this->template('gongdengge');
 }
    public function doMobilegongdengge(){
     global $_GPC,$_W;
     
     include $this->template('gongdengge');
 }




   public function doWebgongdengjilu(){
     global $_GPC,$_W;
      
     include $this->template('gongdengjilu');
 }

   public function doMobilegongdengjilu(){
     global $_GPC,$_W;
      
     include $this->template('gongdengjilu');
 }




 public function doWebgongdengbang(){
     global $_GPC,$_W;
    global $_GPC, $_W;
    $sql = "SELECT * FROM".tablename('bang')."WHERE have > 7";
    $list = pdo_fetchall($sql);
     include $this->template('gongdengbang');
 }

 public function doMobilegongdengbang(){
     global $_GPC,$_W;
       global $_GPC, $_W;
    $sql = "SELECT * FROM".tablename('bang')."WHERE have > 7";
    $list = pdo_fetchall($sql);
     include $this->template('gongdengbang');
 }






  public function doWebguanyu(){
     global $_GPC,$_W;
      
     include $this->template('guanyu');
 }
 public function doMobileguanyu(){
     global $_GPC,$_W;
      
     include $this->template('guanyu');
 }
/*    public function doWebgongdengfenxiang(){
     global $_GPC,$_W;
      
     include $this->template('gongdengfenxiang');
 }*/
  public function doMobilegongdengfenxiang(){
     global $_GPC,$_W;
      
     include $this->template('gongdengfenxiang');
 }
 public function doWebfenxiangshezhi(){
		global $_GPC;
		$do = !empty($do) ? $do : 'display';
		$do = in_array($do, array('display', 'post', 'delete', 'fetch', 'check')) ? $do : 'display';
		//post方法为添加页的显示，和编辑页的显示
		if($_GET['act']=='post'){
			$do='post';
		}
		if($_GET['act']=='add'){
			$do='add';
		}
		if($_GET['act']=='delete'){
			$do='delete';
		}
		if($_GET['act']=='edit'){
			$do='edit';
		}
		//贡品类别列表
		if ($do == 'display') {
			$category = pdo_fetchall("SELECT * FROM ".tablename('fenxiangshezhi')." WHERE class_id ORDER BY class_id asc");
			include $this->template('gongdengfenxiang');
		}
		//添加贡品分类到数据库
		elseif($do == 'add'){
			$classname = $_POST['classname'];
			$data = array( 
				'classname'   => $classname
			);
			pdo_insert('fenxiangshezhi', $data);
			message('保存成功',$this->createWebUrl('gongdengfenxiang'),'success');

		}
		//删除贡品类别
		elseif($do == 'delete'){
			$class_id = $_GET['class_id'];
			$row = pdo_fetch("SELECT class_id FROM ".tablename('gongdeng')." WHERE class_id = ".$class_id);
			if (empty($row)) {
				message('抱歉，类别不存在或是已经被删除！');
			}
			$data = array(
				'class_id' => $class_id
			);
			pdo_delete('fenxiangshezhi', $data);
			message('删除成功',$this->createWebUrl('gongdengfenxiang'),'success');

		}
		//添加或修改贡品类别
		elseif($do == 'post'){
			$class_id = $_GET['class_id'];
			if($class_id){ //更新贡品类别页
				$category = pdo_fetch("SELECT * FROM ".tablename('fenxiangshezhi')." WHERE class_id = ".$class_id);
				if(empty($category)) {
					message('分类不存在或已删除', '', 'error');
				}else{
					$classname = $_GET['classname'];
					$edit = 1;
					$this->assign('edit',$edit);
					$this->assign('class_id',$class_id);
					$this->assign('classname',$classname);
					include $this->template('gongdengfenxiang');
				}
			}
			else{  //添加贡品类别页
				include $this->template('gongdengfenxiang');
			}
		}
		elseif($do == 'edit') {
			$class_id = intval($_GET['class_id']);
			$classname = $_POST['classname'];
			$data = array(
				'classname' => $classname
			);
			$where = 'class_id ='.$class_id;
			pdo_update('fenxiangshezhi',$data,$where);
			message('更新分类成功！',$this->createWebUrl('gongdengfenxiang'), 'success');
		}
		exit('error');
	}
public function doWebgongdengfenxiang(){
		// uni_user_permission_check('imeepos_fvoice_news');
		//获取全部贡品
		//print_r($_GET['act']);die('aa');
		global $_GPC;
		$do = in_array($do, array('display', 'post', 'delete')) ? $do : 'display';
		if($_GET['act']=='post'){
			$do = 'post';
		}
		if($_GET['act']=='add'){
			$do = 'add';
		}
		if($_GET['act']=='delete'){
			$do = 'delete';
		}
		if($_GET['act']=='edit'){
			$do = 'edit';
		}
		$news = pdo_fetchall("SELECT * FROM ".tablename('gongdengfenxiang')." WHERE id ORDER BY id DESC");
		//贡品列表（默认）
		if($do == 'display') {
			$pindex = max(1, intval($_GPC['page']));
			$psize = 20;
			$params = array();
             $glist = pdo_fetchall("SELECT * FROM ".tablename('fenxiangshezhi'));
			//分页
            $cid = $_GET['cid'];
            $list = pdo_fetchall("SELECT * FROM ".tablename('gongdengfenxiang')." WHERE class_id = 1 ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize);

            if($cid == 1){
                $list = pdo_fetchall("SELECT * FROM ".tablename('gongdengfenxiang')." WHERE class_id = 1 ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize);
            }elseif($cid == 2){
                $list = pdo_fetchall("SELECT * FROM ".tablename('gongdengfenxiang')." WHERE class_id = 2 ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize);
            }elseif($cid == 3){
                $list = pdo_fetchall("SELECT * FROM ".tablename('gongdengfenxiang')." WHERE class_id = 3 ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize);
            }
			foreach($list as $key => $c){
				$classname=pdo_fetch("SELECT classname FROM ".tablename('fenxiangshezhi')." WHERE class_id = ".$c['class_id']);
				$list[$key]['classname'] = $classname['classname'];
			}
			$total = count($list);
			$pager = pagination($total, $pindex, $psize);
			include $this->template('gongdengfenxiang');
		}
		//添加贡品、系统消息的页
		if($do == 'post') {
            $msg = $_GET['msg'];
            if($msg){
                $id = $_GET['id'];
                if (!empty($id)) { //当前为编辑系统消息
                    $item = pdo_fetch("SELECT * FROM ".tablename('gongdengfenxiang')." WHERE id = :id" , array(':id' => $id));
                    $classfind = pdo_fetch("SELECT class_id,classname FROM ".tablename('fenxiangshezhi')." WHERE class_id = :class_id" ,
                        array(':class_id' => $item['class_id']));
                    $class = pdo_fetchall("SELECT * FROM ".tablename('fenxiangshezhi')." WHERE class_id ORDER BY class_id DESC");
                    if(empty($item)){
                        message('抱歉，文章不存在或是已经删除！');
                    }else{
                        $edit = 1;
                        $this->assign('edit',$edit);
                        $this->assign('id',$id);
                        $this->assign('classfind',$classfind);
                        $this->assign('item',$item);
                        $this->assign('class',$class);
                        include $this->template('msg');
                    }

                } else {//添加系统消息
                    $classfind = pdo_fetch("SELECT class_id,classname FROM ".tablename('fenxiangshezhi')." WHERE class_id = 3");
                    $getclass['class_id'] = $classfind['class_id'];
                    $getclass['classname'] = $classfind['classname'];
                    include $this->template('msg');
                }
            }else{
                $id = $_GET['id'];
                if (!empty($id)) { //当前为编辑贡品
                    $item = pdo_fetch("SELECT * FROM ".tablename('gongdengfenxiang')." WHERE id = :id" , array(':id' => $id));
                    $classfind = pdo_fetch("SELECT class_id,classname FROM ".tablename('fenxiangshezhi')." WHERE class_id = :class_id" ,
                        array(':class_id' => $item['class_id']));
                    $class = pdo_fetchall("SELECT * FROM ".tablename('fenxiangshezhi')." WHERE class_id ORDER BY class_id DESC");
                    if(empty($item)){
                        message('抱歉，文章不存在或是已经删除！');
                    }else{
                        $edit = 1;
                        $this->assign('edit',$edit);
                        $this->assign('id',$id);
                        $this->assign('classfind',$classfind);
                        $this->assign('item',$item);
                        $this->assign('class',$class);
                        include $this->template('gongdengfenxiang');
                    }

                } else {
                    $getclass['class_id'] = $_GET['class_id'];
                    $getclass['classname'] = $_GET['classname'];
                    $class = pdo_fetchall("SELECT * FROM ".tablename('fenxiangshezhi')." WHERE class_id ORDER BY class_id DESC");
                    $this->assign('class',$class);
                    $this->addign('getclass',$getclass);
                    include $this->template('gongdengfenxiang');
                }
            }
			
		}
		//添加贡品到数据库
		if($do == 'add'){
            $msg = $_GET['msg'];
            if($msg){
                if (empty($_GPC['title'])) {
                    message('标题不能为空，请输入标题！');
                }
                $classfind = pdo_fetch("SELECT class_id,classname FROM ".tablename('fenxiangshezhi')." WHERE class_id = 3");
                $data = array(
                    'class_id'   => $classfind['class_id'],         //classname在前台显示的值是名字，value值是class_id
                    'title'      => addslashes($_GPC['title']),
                    'prise'      => $_GPC['prise'],
                    'content'    => htmlspecialchars_decode($_GPC['content'], ENT_QUOTES),
                    'image'      => $_GPC['thumb'],
                    'createtime' => time()
                );
                pdo_insert('gongdengfenxiang', $data);
                message('保存成功',$this->createWebUrl('gongdengfenxiang'),'success');
            }else{
                if (empty($_GPC['title'])) {
                    message('标题不能为空，请输入标题！');
                }
                $data = array(
                    'class_id'   => intval($_GPC['classname']),         //classname在前台显示的值是名字，value值是class_id
                    'title'      => addslashes($_GPC['title']),
                    'prise'      => $_GPC['prise'],
                    'content'    => htmlspecialchars_decode($_GPC['content'], ENT_QUOTES),
                    'image'      => $_GPC['thumb'],
                    'createtime' => TIMESTAMP
                );
                pdo_insert('gongdengfenxiang', $data);
                message('保存成功',$this->createWebUrl('gongdengfenxiang'),'success');
            }
                

		}
		//编辑贡品
		if($do == 'edit'){
			$data = array(
				'class_id'   => intval($_GPC['classname']),         //classname在前台显示的值是名字，value值是class_id
				'title'      => addslashes($_GPC['title']),
				 'prise'      => $_GPC['prise'],
				'content'    => htmlspecialchars_decode($_GPC['content'], ENT_QUOTES),
				'image'      => $_GPC['thumb'],
				'createtime' => TIMESTAMP
			);
			$where = 'id = '.$_GET['id'];
			pdo_update('gongdengfenxiang', $data , $where);
			message('贡品更新成功！',$this->createWebUrl('gongdengfenxiang'),'success');

		}
		//删除贡品
		if($do == 'delete') {
			$id = intval($_GET['id']);
			$row = pdo_fetch("SELECT id FROM ".tablename('gongdengfenxiang')." WHERE id = ".$id);
			if (empty($row)) {
				message('抱歉，贡品不存在或是已经被删除！');
			}
			$data = array(
				'id' => $id
			);
			pdo_delete('gongdengfenxiang', $data);
			message('删除成功',$this->createWebUrl('gongdengfenxiang'),'success');

		}
	}


















 //bofo yanli
 public function doMobilegong(){
    global $_GPC, $_W;
     
   include $this->template('gong');  
 } 
 public function doMobilegongpin(){
    global $_GPC, $_W;
    // 花篮
    $sql = "SELECT * FROM".tablename('imeepos_fvoice_news')."WHERE class_id = 1";
    $hualan = pdo_fetchall($sql);
    // 香炉
    $sql = "SELECT * FROM".tablename('imeepos_fvoice_news')."WHERE class_id = 2";
    $xianglu = pdo_fetchall($sql);
    //果盘
    $sql = "SELECT * FROM".tablename('imeepos_fvoice_news')."WHERE class_id = 3";
    $guopan = pdo_fetchall($sql);    
    
   include $this->template('gongpin');  
 } 
 public function doMobilehuiinfo(){
    global $_GPC, $_W;
    $act = $_GPC['act'];
    if($act == 't'){
        $data = array(
            'fozi' => $_GPC['fozi'],
            'give' => $_GPC['give'],
            'name' => $_GPC['name'],
        );        
      $info =  pdo_insert('huixiang',$data);
      $_SESSION['data'] = $data;
      if($info){
         
          header("Location:{$this->createMobileUrl('huicontent')}");
          exit();
      }
    }
   include $this->template('huiinfo');  
 } 
 public function doMobilehuicontent(){
    global $_GPC, $_W;
    $fozi =  $_SESSION['data']['fozi'];
    $give =  $_SESSION['data']['give'];
    $name =  $_SESSION['data']['name'];
   include $this->template('huicontent');  
 } 
 public function doMobilebang(){
     global $_GPC, $_W;
    $sql = "SELECT * FROM".tablename('bang')."WHERE have > 7";
    $list = pdo_fetchall($sql);
     
   include $this->template('bang');  
 } 
 public function doMobilemy(){
     global $_GPC, $_W;
   include $this->template('my');  
 } 
 public function doMobilemyjilu(){
    global $_GPC, $_W;
   include $this->template('myjilu');  
 } 
 public function doMobilemypaiwei(){
    global $_GPC, $_W;
   include $this->template('mypaiwei');  
 }

 //end





    public function doWebshouldknow(){
        if($_GET['push']){
            $content = $_POST['content'];
            $data = array(
                'content' => $content
            );
            pdo_update('shopping_shouldknow', $data, array('id' => 1));
            $item = pdo_fetch("SELECT * FROM ".tablename('shopping_shouldknow')." WHERE id = 1");
            message('保存成功',$this->createWebUrl('shouldknow'),'success');
        }else{
            $item = pdo_fetch("SELECT * FROM ".tablename('shopping_shouldknow')." WHERE id = 1");
            include $this->template('shouldknow');
        }
    }
    public function doMobilecase_detail(){
        global $_GPC, $_W;
        $id = $_GET['id'];
        if($_GET['yidu']){
            pdo_update('shopping_order', array('yidu' => 1), array('id' => $id));
        }
        //会员无法鉴定未读 cqn
        if($_GET['status']==-1 && $_GET['yidu']==1)
        {
            pdo_update('shopping_order', array('wfjd' => 1), array('id' => $id));
         }
         if($_GET['zjyjd']==1)
         {
         	pdo_update('shopping_order', array('zjyjd' => 1), array('id' => $id));
         }
        $status = $_GET['status'];
        $orderimgs = pdo_fetch("SELECT * FROM ".tablename('shopping_order')." WHERE id = ".$id);
        $paishjian = date('Y/m/d H:i:s', $orderimgs['paishjian']);
        pdo_query("update " . tablename('shopping_order') . " set shownum=shownum+1 where id=:id ", array(":id" => $id));
        $orderimg = unserialize($orderimgs['upimg']);
        $order = $orderimgs;
        $item = pdo_fetchall("SELECT * FROM ".tablename('shopping_order')." WHERE id =:id",array(":id" => $id));
        $item = $item[0];
        $user = pdo_fetchall("SELECT * FROM ".tablename('mc_members')." WHERE openid =:openid",array(":openid" => $item['from_user']));
        $avatar = $user[0]['avatar'];
        //专家信息
        $openid = $item['zjopenid'];
        $expert = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE openid =:openid",array(":openid" => $openid));
        $category = pdo_fetch("SELECT * FROM ".tablename('shopping_category')." WHERE id =:id",array(":id" => $expert['pcate']));
        $expert['pcate'] = $category['name'];
        $comment = pdo_fetch("SELECT * FROM ".tablename('shopping_comment')." WHERE orderid =:orderid AND shows = '1'", array(":orderid" => $id));
		$voice = pdo_fetch("SELECT * FROM ".tablename('shopping_order_voice')." WHERE orderid = :id", array(":id" =>$id));
        $act = trim($_GPC['act']);
        if($act == 'src'){
			$goodid= $_GPC['goodid'];
			$collect =  pdo_fetch("SELECT * FROM ".tablename('shopping_goods_collect')." WHERE openid = :openid and goodid = :goodid", array('openid'=>$_W['openid'],'goodid'=>$goodid));
			$total = pdo_fetchcolumn("select count(*) from " .tablename("shopping_goods_collect")." where goodid=".$goodid);
          
			if($collect){
				$datacollect = array();
				$shopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$goodid));
				$total -=1;
				pdo_update("shopping_goods", array('collect'=>$shopclass['collect']), array("id" => $goodid));
				
				pdo_delete('shopping_goods_collect', array('id'=>$collect['id']));
				$datacollect['status'] = 1;
				$datacollect['num']  = $total;
				die(json_encode($datacollect));
			}else{
				$datacollect = array();
				$shopclass = pdo_fetch("SELECT * FROM ".tablename('shopping_goods')." WHERE id = :id", array('id'=>$goodid));
				//var_dump($shopclass);
				if(($shopclass['goodid']==$goodid) && ($shopclass['openid']==$_W['openid'])){
					pdo_delete('shopping_goods_collect', array('id'=>$collect['id']));
					$total -=1;
					$datacollect['status'] = 1;
					$datacollect['num']  = $total;
					die(json_encode($datacollect));
				}else{

					$total +=1;
					pdo_update("shopping_goods", array('collect'=>$shopclass['collect']), array("id" => $goodid));
					$data['goodid'] = $goodid;
					$data['openid'] = $_W['openid'];
					$data['created_at'] = time();
					pdo_insert('shopping_goods_collect', $data);
					$datacollect['status'] = 2;
					$datacollect['num']  = $total;
					die(json_encode($datacollect));
				}
			} 
		}
        $goodscollect = pdo_fetchall("select openid from ".tablename('shopping_goods_collect')." where goodid=".$expert['id']);
            //var_dump($goodscollect);
            foreach ($goodscollect as $key => $value) 
            {
            	if($value['openid']==$_W['openid']){
            		$havecollect=1;
            	}
            }
        include $this->template('case_detail');
    }
public function doWebhui(){
    global $_W,$_GPC;
    $sql = "SELECT * FROM".tablename('huixiang');
    $list = pdo_fetchall($sql);
    $act = $_GPC['act'];
    $id =$_GPC['id'];
    if($act == "delete"){
        pdo_delete('huixiang',array('id'=>$id));
        message('删除成功！', $this->createWebUrl('hui'), 'success');
        
    }
     include $this->template('hui');
}
public function doWebbang(){
    global $_W,$_GPC;
    $sql = "SELECT * FROM".tablename('bang');
    $list = pdo_fetchall($sql);
    $act = $_GPC['act'];
    $id =$_GPC['id'];
    if($act == "delete"){
        pdo_delete('bang',array('id'=>$id));
        message('删除成功！', $this->createWebUrl('bang'), 'success');
        
    }elseif($act == "edit"){
        $id = $_GPC['id'];
        $sql = "SELECT * FROM".tablename('bang')."WHERE id={$id}";
        $info = pdo_fetch($sql);
        $e = $_GPC['e'];
        if($e){
            $have = $_GPC['have'];
            $had = $_GPC['had'];
            $info = pdo_update('bang',array('have'=>$have,'had'=>$had),array('id'=>1));
            if($info){
             message('修改成功！', $this->createWebUrl('bang'), 'success');
            }
        }
        include $this->template('editbang');     
    }else{
        include $this->template('bang');        
    }
    
        
    
}

    //后台查openid
        public function doWebsearchopenid(){
        global $_W,$_GPC;
        if($_W['ispost']){
            $phone = $_GPC['phone'];
            $onload = pdo_fetch("SELECT * FROM " . tablename('mc_members') . " WHERE mobile = :mobile ", array(':mobile' => $phone));
            if(!$onload){
                $user = pdo_fetch("SELECT * FROM " . tablename('shopping_goods') . " WHERE phone = :phone ", array(':phone' => $phone));
                if(!$user){
                    $data['status'] = 0;
                    die(json_encode($data));
                }else{
                    $data['status'] = 1;
                    $data['openid'] = $user['openid'];
                    die(json_encode($data));
                }
            }else{
                $data['status'] = 1;
                $data['openid'] = $onload['openid'];
                die(json_encode($data));
            }
        }else{
            include $this->template('searchopenid');
        }
    }
}
